I really like to do work on my Linux systems as “root”, to get things done quickly and without any hassle. Yeah i know, bombs away, it is not OK or safe or whatever to use “root” user for everyday things but mainly it is not OK from the auditing point of view. Customers really dislike it when you work on any system as “root” user because they can not exactly pin point who did what – your actions are not “recorded”. Any decent company has a company policy that will strictly disallow performing any work as “root” user. But also there are definitely things that just can’t be done with “sudo” and require using “root” user.
Not being “root” and using “sudo” before every command you issue certainly has it’s “disadvantages” – it’s just not the same.
When running “sudo ll” on a normal CentOS/RHEL system you get a “sudo: ll: command not found” error as follows:
[mitch@geekpeek ~]$ sudo ll /home/secret sudo: ll: command not found
This is really crappy and killing your productivity since you are slowed down by such irrelevant problems, but there is a simple fix for this specific problem “sudo: ll: command not found”.
Fix “sudo: ll: command not found”
1. Edit ~/.bashrc file
Work around this problem simply by editing the users ~/.bashrc file and appending the following line at the end of it:
alias sudo='sudo '
2. Open a new Shell session
Close the current SSH session and reconnect or open up a new one. Once you’ve reconnected try the command again
[mitch@geekpeek ~]$ sudo ll /home/secret/ total 0 -rw-rw-r--. 1 secret secret 0 Jul 22 12:44 myfile
Voila, you can use bash aliases with “sudo” command now.
Here’s an additional explanation why “sudo: ll: command not found” problem appears. You can find an answer for this in the bash manual. What matters is the following:
“The first word of each simple command, if unquoted, is checked to see if it has an alias.”
“If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.”
So what bash actually does is only check the first word of a command for alias. If we create an additional alias and put a blank space after command it will check the second word for alias therefore – alias sudo=’sudo ‘ makes bash check the second command for alias when using “sudo”.