Bash – Colored Bash Not Working as Root User

bashcolorsshell

I have noticed that when I ssh to a server and then su to the root user, I do not get color in bash. In this specific case when I say "do not get color in bash" I am talking about editing files with vim. Now, if I sudo after login I get color, so no problems there. If I su to root and source /root/.bash_profile then I get color as root. But I do not want to have to source .bash_profile file every time I su to root. Here are the contents of my /root/.bashrc and /root/.bash_profile files. What can I do to get color when doing su?

# .bashrc

# User specific aliases and functions

# You may uncomment the following lines if you want `ls' to be     colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'


# Source global definitions
if [ -f /etc/bashrc ]; then
     . /etc/bashrc
fi

=============================================

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
alias vi='/usr/bin/vim'
alias grep='/bin/grep --color'
export EDITOR=/usr/bin/vim

# HISTSIZE = number of lines in memory while session is ongoing
# HISTFILESIZE = maximum number of lines in the history file on   disk
export HISTSIZE=3000
export HISTFILESIZE=5000
export HISTFILE=/root/history/.bash_hist-$(who -m | awk '{print   $1}')

Best Answer

Either use su - to get a login shell, or move the aliases to ~/.bashrc. See: Answer on SuperUser

Related Question