Sudo doesn't work on Aliases [duplicate]

I have added alias ll='ls -la' in /etc/bash.bashrc but sudo ll is not working. Is there a way to "source" bash.bashrc? In a related post, another user suggesting creating an alias for sudo with a space after it. Eg. alias sudo='sudo ' but there wasn't any context to this answer. Should I add this to my bashrc? Seems hackish.

What is the correct method for adding an alias for my sudo one-off commands?


Solution 1:

Yes, adding the alias sudo='sudo ' line will fix your problem. For a better definition (from the bash manual),

Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands.

The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias. The characters ‘/’, ‘$’, ‘`’, ‘=’ and any of the shell metacharacters or quoting characters listed above may not appear in an alias name. The replacement text may contain any valid shell input, including shell metacharacters. The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias ls to "ls -F", for instance, and Bash does not try to recursively expand the replacement text. 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.

One way you can be sure is typing it in a terminal window.

If you do it this way, the changes aren't permanent, they only exist until you close/logout of the terminal.

I think, in your case, it would be safer to add the changes to ~/.bashrc instead of /etc/bash.bashrc, but it really doesn't make much of a difference.