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 execute it 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.
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.
You can get that done in the same way as you would do it for other users:
~/.bashrc
file (for root user the absolute path is/root/.bashrc
);~/.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.