How to save root aliases permanently?
i tried saving aliases (see below) for the root user in .bash_profile
to /var/root/.bash_profile and restarting Terminal, but it didn't work. where does the .bash_profile
file need to be to maintain persistent aliases in the terminal?
$ cat /var/root/.bash_profile
alias grep='grep --color=always'
alias net='sudo netstat -ap tcp && sudo lsof -Pn -i4'
my specifications:
sh-3.2# system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: OS X 10.8.5 (12F45)
Kernel Version: Darwin 12.5.0
Boot Volume: lily
Boot Mode: Normal
Computer Name: lily’s MacBook Air
User Name: System Administrator (root)
Secure Virtual Memory: Enabled
Time since boot: 12:37
The proper config file name of the standard root shell (i.e. sh) is .profile. So change the name of .bash_profile to .profile:
mv /var/root/.bash_profile /var/root/.profile
source /var/root/.profile
This is working logging in as root in the GUI.
Trying to sudo su
in a sudoer's shell won't fetch root's .profile file. Use sudo -i
instead.
sudo ln -s "/Users/${LOGNAME}/.bash_profile" /var/root/.profile
Result:
$ sudo ls -lha /var/root/.profile
lrwxr-xr-x 1 root wheel 24B Oct 5 12:40 /var/root/.profile -> /Users/phx/.bash_profile
Then your own ~/.bash_profile
will load for root when you sudo -s
or sudo -i
(along with your functions and aliases).
I have not been able to get this to work for one-off sudo
commands, however.