Friday, May 23, 2014

Setup color for ls command

Linux shell terminal uses dircolors to manage the color scheme. To change the color setting for the ls output, we can do the following.

Step 1 Add the following into file ~/.bashrc so that the changes will be made permanent

if [ "$TERM" != "dump" ]; then
        if [ -e $HOME/.dircolors ]; then
                eval "`dircolors -b $HOME/.dircolors`"
        fi
fi

Step 2 Print current color scheme and save it to file ~/.dircolors

dircolors -p >~/.dircolors

Step 3 Edit color settings for different file types as specified in file ~/.dircolors, e.g., change the color code for directory as "DIR 01;36" where 01 stands for bold font face and 36 indicates cyan for text color.

Step 4 Test  the changes

source ~/.bashrc
ls -l ~/