Friday, March 24, 2006

Changing the colour of ls command in Linux

Configuration file for ls colour command is /etc/DIR_COLORS for linux. You can modify it if you want.
Here is a list of common colours
Normal file : Normal
Directory: Blue
Symbolic link : Cyan
Pipe: Yellow
Socket: Magenta
Block device driver: Bold yellow foreground, with black background
Character device driver: Bold yellow foreground, with black background
Orphaned syminks : Blinking Bold white with red background
Missing links ( - and the files they point to) : Blinking Bold white with red background
Archives or compressed : Red (.tar, .gz, .zip, .rpm)
Image files : Magenta (.jpg, gif, bmp, png, tif)

They are stored in a special environment variable called LS_COLORS.
You can customized them in /etc/DIR_COLORS or file pointed by shell variable COLORS.
To customized colours you must use special string combination:
FILE-TYPE Attribute codes: Text color codes:Background color codes
where
FILE-TYPE: is file type like DIR (for directories)
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

for example: an entry for dir will look like
DIR 01;34
Now open /etc/DIR_COLORS using
# vi /etc/DIR_COLORS
Modify DIR entry to
DIR 01;34;41 # NEW default is Bold blue with RED background
save the file
Try other alternatives if you want.
You may need ti logout and login back to make changes to effect.
Or run the command 'eval `dircolors -b /etc/DIR_COLORS`' .

No comments: