Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to execute a command for my system to search for new sd cards and to be able to execute it I need to me logged on as root. Simply using sudo with the command does not work. This is not a question of how to execute an alias with sudo rights!
I want to know how to add an alias to the root user so I can execute it after using sudo -i. I tried logging in to the root user and just adding the alias (which works fine). The only problem is that the alias disappears after I log out from the terminal.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You should add that alias command line to .bashrc file in /root folder and not in /home/user/.bashrc(this .bashrc file belongs to user account not root).

By doing so .bashrc file in /root is run at root login, your alias command will be automatically created every time.

So that you can use your alias command directly in shell when logged in as root.

share|improve this answer
    
thanks it worked. –  Arno van der Weijden Jul 7 at 15:36

You can get that done in the same way as you would do it for other users:

  1. By adding the new alias to the user's ~/.bashrc file (for root user the absolute path is /root/.bashrc);
  2. (Preferred method as you can have all custom aliases and functions under one file.) By creating, if it is not there, and adding the new alias to the user's ~/.bash_aliases file (for root you'd create /root/.bash_aliases).

(Note: You can also add/append new function definations in the same way as mentioned for aliases above.)

For an example you can check this link.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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