« HOME

Changing colors of ls

By Nacho Martín on 05 May 2010

I have been quite a long time living with files with 777 permission being displayed in blue over green background whenever I do ls, which makes text quite illegible. Sometimes you don’t see a problem even when it is in front of you. Well, I took the time to fix it today. Here is the solution:

dircolors --print-database &> ~/.dircolors

It will create a .dircolors file with the color specification vim .dircolors. Now we edit this file and change this line:

OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky

for this one:

OTHER_WRITABLE 01;37;42 # dir that is other-writable (o+w) and not sticky

That will tell ls to display these files with white bold letters over green background, mucho more legible.

In case you prefer different colors, here is what these codes mean:

# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

Last step is to edit ~/.bashrc to make dircolors load these colors each time a new term is opened. Open .bashrc and add these lines:

if [ -x /usr/bin/dircolors ]; then
 d=.dircolors
 test -r $d && eval "$(dircolors $d)" || eval "`dircolors -b`"
fi

Open a new terminal to see the changes o just run

source .bashrc

If you want to see the changes applied in the current terminal.

Written by @nacmartin

blog comments powered by Disqus

» ALL POSTS