Colourful file listings in the terminal

If you are bored of the plain black and white colour file listings when you type „ls“ in your Terminal, you can actually make the ls command colour the files based on their type (not mime type, but directory, symlink, etc) and extension.
If you add the switch -C or –color to the ls command (i.e.)

ls -F -color

then you should get somewhat more interesting output!
If you want to have some control over the colours that are displayed for each file type, create a file called .dircolours (or similar) in your home directory containing an entry for each terminal type (i.e. beterm or xterm) and the list of file extensions along with their colours. The example below demonstrates how this works.

TERM beterm
TERM xterm
NORMAL 00 # global default, although everything should be something.
FILE 00 # normal file
DIR 00;32 # directory
LINK 01;36 # symbolic link
FIFO 40;33 # pipe
SOCK 01;35 # socket
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
EXEC 01;33
*~ 05;31 # stuff we hate to find laying around (flashing red)
.c 00;35 # source code
.cpp 00;35
.h 00;36
.pl 00;35
.pm 00;35
.cgi 00;35
.html 04;35
.tar 00;31 # archives or compressed (bright red)
.tgz 00;31
.arj 00;31

Once you have saved this file somewhere you need to add the following commands to your .profile (or .bashrc is probably better), replacing the .dircolours filename with whatever you used…

eval `dircolors ~/.dircolours`
alias ls='ls --color=always'


No comments so far.

(comments are closed)