Command-Line – Why Alias in /etc/bash.bashrc Not Apply to Sudo

aliasbashrccommand linerootsudo

I've added the line

alias ll='ls -l'

to the /etc/bash.bashrc. After a restart, the alias ll from that file affects me, which I checked by commenting out the corresponding alias in my ~/.bashrc (and logging out and back in after that edit). However, it seems to not affect root, as when I type sudo ll, I get "no such command". Shouldn't the alias work in any situation if it's in the system-wide .bashrc?

Best Answer

sudo will ignore any aliased commands from .bashrc.

You can work around this by creating an alias for sudo too --> alias sudo='sudo '

You need the space after sudo, since man tells us:

If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.
Related Question