With a little side of applesauce...

Thursday, February 1, 2007

changing directory listing colors

Just figured out how to customize the coloring of directory listings in BASH.

1. dircolors = command used to print out color configuration to STDOUT. (use “–print-database” to print out ALL configuration settings).
2. LS_COLORS = environment variable used to set dircolor configuration for BASH


1. create new file containing contents of current LS_COLORS envvar

dircolors > ~/.bash_dircolors

2. modify the contents of ~/.bash_dircolors according to the following key:

Attribute codes are 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed, text color codes are 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white, and background color codes are 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white. Here are the some useful types:

no: normal, global default, although everything should be something.
fi: normal file
di: directory
ln: symbolic link
pi: FIFO, pipe
so: socket
bd: block device driver
cd: character device driver
or: orphan, symlink to nonexistent file
ex: files with execute permission


3. source the file to test:

source ~/.bash_dircolors

4. When happy with changes, add the following to .bash_profile, to source .bash_dircolors when you login:

# include .bash_dircolors if it exists
if [ -f ~/.bash_dircolors ]; then
. ~/.bash_dircolors


1. Here is an example of the LS_COLORS

export LS_COLORS

2. To add a background color, change the following:




No comments: