I have set aliases for a few programs in the .bashrc file, and they work fine without sudo and they don't with sudo.

Is there a way to get those aliases work with sudo?

For example:

nano text.txt #alias nano='nano -icB' WORKS
sudo nano text.txt #alias does not work

NOTE: I have tried sudo -E nano text.txt, but it didn't work.

I am on Ubuntu 15.04 (Vivid Vervet).


One way is to duplicate your aliases for the root user, too. By e. g. putting them in /root/.bashrc.

Perhaps an easier way is to simply put this in your .bashrc:

alias sudo='sudo '

The space after sudo is important. According to the bash manual:

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.

  • how can sudo with a space after it can help? Oct 11 '15 at 10:05
  • Again, please see the updated answer. That's a feature of bash.
    – A.P.
    Oct 11 '15 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.