Your user ID's aliases are not used via sudo
You may or may not want to use the trick linked to in the comments.
There might be reasons to have no aliases or other aliases for root
.
These aliases can be stored in /root/.bashrc
as you already know. They can be used when you run interactively at the root prompt #
after
sudo -i # activates root's aliases
but they are not activated when followed by the alias on the command line
sudo -i <specific alias> # does not activate root's aliases
sudo -H <specific alias> # does not activate root's aliases
Examples:
$ LANG=C sudo -i
root@xenial32:~# alias
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
root@xenial32:~# grep -e ^alias -e \ alias /root/.bashrc
enable color support of ls and also add handy aliases
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
Using one of root
's aliases
root@xenial32:~# l
bin@ extractor.log logfile.tar mkusb.log
root@xenial32:~# exit
logout
sudodus@xenial32 ~ $ LANG=C sudo -i l
-bash: l: command not found
[127] sudodus@xenial32 ~ $ LANG=C sudo -H l
sudo: l: command not found
[1] sudodus@xenial32 ~ $ LANG=C sudo -i alias
sudodus@xenial32 ~ $
I would not use alias sudo='sudo -i'
because
there is a risk, that you forget that you have superuser privileges, and may do things that you should only do with regular privileges. In other words, I would say that it defeats the purpose of sudo
to always go to root prompt
an alias does not work anyway on the command line with sudo -i <specific alias>
it is often efficient to use sudo
with the standard settings for text mode commands
for GUI commands I would recommend sudo -H
or gksudo
root
. – sudodus Nov 09 '17 at 13:00/root/.bashrc
– derHugo Nov 09 '17 at 13:02sudo -i
(and get the root prompt). – sudodus Nov 09 '17 at 13:40sudo -i
pressedEnter
and did my stuff (e.g.nano ./.configFile
) as root. Now that you mention it I tried to do justsudo -i nano /root/.configFile
which works fine , too. Is it a good Idea than to use an alias asalias sudo='sudo -i'
or speaks anything against this? – derHugo Nov 09 '17 at 16:27