Bash – Why root bash output is colored but `sudo ls` output is not

aliasbashlsshellsudo

In bash (I am using Ubuntu 12.04) I get colored outputs either as root (after sudo su) or as a normal user.

I checked (after reading this post) the files .bashrc for normal user and superuser and the options related to color are enabled for ls in alias ls='ls --color=auto' which makes sense.

But when using sudo ls I get no colored output at all. Why is that? and how to enable it permanently?

Best Answer

You can reenable aliases as described at https://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo

the short version is to add and alias for sudo as

alias sudo='sudo '

to get it to check the rest of the command for aliases. Otherwise, the sudo is check to see if it's an alias, it is not, so the rest of the alias checking ends. If sudo is an alias and ends in a space though, the next parts will also be checked to see if they are aliases, which is what you need to get the ls alias to be evaluated

Related Question