Changing the colour of directory listings in FreeBSD & ZSH

By default when you use ls to list the contents of a directory you only get the output below.

image_048

I’ve made this a little more pretty by adding the following to my ~/.zshrc file

alias ls=”ls -GF”

The output now is easier to read but it has an issue where all the directories are using blue. This isn’t very readable on a black background.

image_049

I’ve lived with this for long time. Today I discovered a easy way to fix only the colours of the directories.

The default colour scheme ls uses to display the contents of a folder is “exfxcxdxbxegedabagacad”. This is decoded as follows:

The color designators are:

a     black
b     red
c     green
d     brown
e     blue
f     magenta
g     cyan
h     light grey
A     bold black, usually shows up as dark grey
B     bold red
C     bold green
D     bold brown, usually shows up as yellow
E     bold blue
F     bold magenta
G     bold cyan
H     bold light grey; looks like bright white
x     default foreground or background

Note that the above are standard ANSI colors.  The actual display may differ depending on the color capabilities of the terminal in use.

The order of the attributes are:

1.   directory
2.   symbolic link
3.   socket
4.   pipe
5.   executable
6.   block special
7.   character special
8.   executable with setuid bit set
9.   executable with setgid bit set
10.  directory writable to others, with sticky bit
11.  directory writable to others, without sticky bit

You can change the default to “hxfxcxdxbxegedabagacad” (ie light grey for the directories, everything else the same) by adding the following to your ~/.zshrc:

LSCOLORS=”hxfxcxdxbxegedabagacad”
export LSCOLORS

The output from ls is now far more readable.

image_050

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s