Run Alias as Sudo in Linux


使用alias时如果某个指令需要sudo权限,则运行alisas会报这个指令not found,解决方法是
在 ~/.bashrc下加入以下一行(注意:sudo 后面有个空格):

alias sudo="sudo "

How does this work?

When running a command, only the first word is checked against your aliases. So myalias by itself will work, but running sudo myalias means that only sudo is checked against your aliases - not the second word myalias.

The trick of aliasing sudo to itself (plus a space!) works because "[when] 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." - from the bash manual