Educating the world

Our blog has over 10,000 readers a month

« Dancing girl optical illusionSpam filtering enhancement to Horde accepted »


Comment from: MightyBigCar [Visitor]
22/11/08 @ 01:11
Comment from: davidnewcomb [Member]  

I don’t think that your reference goes anywhere near describing how to do “Configuring LS_COLORS” but I’ll allow it in for two reasons:
1) the fact that anyone makes a comment is nice!
2) It’s another link to LS_COLORS which is a bit of a complicated affair, so the more links the better.

I know that I get about 400 page views (per month) of this article, but if I mention affair, will I get all the porn hunters looking here? Oh no, I’ve mentioned porn does that mean I’ll get even more? I’ll analyse the blog stats over the next couple of months and let you know… (in another blog!)

22/11/08 @ 01:57
Comment from: ri [Visitor]

i’ve searched in vain for the answer to this: I want to remove sg colors BUT have it use the extension colors instead i.e. ignore the sticky bit. setting sg=00 or removing it from ~/.dir_colors just makes those files black-n-white without the pretty colors by extension.
thanks for any help.

06/12/08 @ 02:53
Comment from: davidnewcomb [Member]  

I’m afraid Ri you are out of luck. The sticky bit takes precedence over the other file types. Once “ls” sees that the file is sticky the extension settings are never read.
It’s an interesting request, you may want to email the GNU team and add it as a feature request or bug.
Try here: GNU FileUtils Project

07/12/08 @ 23:24
Comment from: Rita [Visitor]

Thanks from me and from my eyes!

14/01/09 @ 09:25
Comment from: myname [Visitor]

please add:

97 - White (-:

21/05/09 @ 14:40
Comment from: acne [Visitor]

Colours make it much easier to read .

22/05/09 @ 10:17
Comment from: Wh1mpy [Visitor]

This tut was very useful for me and my eyes. I almost went blind staring at blue letters. Many thanks for you’re effort..

19/07/09 @ 04:02
Comment from: peter [Visitor]  

I see that you can choose file extensions to color, but is there a way to color hidden files for when i do ‘ls -a’ like ‘.cshrc’? It doesn’t accept ‘.*’ as a valid entry.

22/07/09 @ 21:36
Comment from: your lastname [Visitor]
your lastname

Thanks for your great tip! It made my shell colorful!

24/10/09 @ 09:26
Comment from: anthony [Visitor]

I’ve known and used ansi color sequences for a long time now, and this is the first reference to the ‘Extra colours’ that I’ve ever seen.

Sure enough, I tried them out and they all work! Awesome. (now I’m gonna waste a good chunk of time seeing how I can further customize all my syntax highlighting, LS_COLORS, zsh completion menu colors, etc etc…)

Where did you find out about these?

03/11/09 @ 06:53
Comment from: edigitalwholesale [Visitor]

Thanks for good knowledge.
it’s very useful way to change color.

19/01/10 @ 05:15
Comment from: Pete [Visitor]

This was very useful. Thanks for sharing. :-)

21/01/10 @ 15:33
Comment from: ed [Visitor]

Since your solution of :
export LS_COLORS
overwrites a possible existing configuration of LS_COLORS, you can juste substitute the existing definition with sed (stream editor) as follows :

LS_COLORS="`echo $LS_COLORS |sed ’s/di=[0-9]*;[0-9]*/di=01;34/; s/ow=[0-9]*;[0-9]*/ow=01;34/’`”
export LS_COLORS


23/02/10 @ 10:38
Comment from: j tweed [Visitor]
j tweed

You don’t make any mention of ~/.dir_colors or /etc/DIR_COLORS. At least the link provided by MightyBigCar does so, (and there is one in a comment)/ It seems to me that ~/.dir_colors is a convenient place to define colors.

Otherwise, a very useful tutorial.

23/03/10 @ 01:12
Comment from: davidnewcomb [Member]  

Thanks j tweed, you are right. I have added a section describing the dir_colors file.

23/03/10 @ 10:46
Comment from: Rich [Visitor]

Seems like it boils down to this:

1. dircolors –print-database > ~/.dircolors
2. vi .dircolors
3. update bashrc to look for ~/.dircolors (as per info page referenced in “man dircolors")

if [ -x /usr/bin/dircolors ]; then

test -r $d && eval “$(dircolors $d)” || eval “`dircolors -b`”

Thanks for all the info.

21/04/10 @ 21:54
Comment from: Michael Cook [Visitor]
Michael Cook

This was very useful to me cos my old eyes don’t like DIR 1;034 which is the bold blue used by default for directories on my Ubuntu 8.04 Hardy set up. I changed it to bold yellow so now I can see it. Who chooses these things anyway? Thank you!

25/05/10 @ 13:03
Comment from: Adam J [Visitor]
Adam J

I work in an environment where a bunch of users are idiots and make everything 777 or 755. Is there a way to make is so that ex= does not override extensions like *.gz?

04/06/10 @ 18:23
Comment from: Peter Vanderhaden [Visitor]  
Peter Vanderhaden

Love the article, but I do have one question. This seems to work perfectly in OS X, but when I do the exact same thing in Kubuntu 10.04, the first line of the ls -la listing is bright in color, and all the others are colored, but dull. Any ideas?

26/06/10 @ 19:04
Comment from: Rory [Visitor]

You could just look at the man page!

man ls

26/11/10 @ 09:46
Comment from: brian hefele [Visitor]  
brian hefele

I have recently switched from BSD ls to GNU ls, and have been trying to perfect my LS_COLORS — this guide has been a godsend (one of many)…

A couple of things - you are missing at least two key - mh/MULTIHARDLINK for “Regular file[s] with more than one link” and ca/CAPABILITY for “File with capability.”

Also, and I haven’t seen this anywhere, if you’re feeling bold you can use the 256 colors of xterm instead of ANSI colors. You want to set the value of the key to the whole xterm escape sequence, as in \033[38;5;159. 38 there refers to foreground, 48 would be background. 159 is the color. Colors can be separated w/ the letter ‘m’, and ANSI escapes for underline, bold, flash, etc. can also be tacked on with an ‘m,’ as in \033[38;5;159m\e[04 (same as above, only underlined.)

I dread that the above will get eaten in the commenting process… :)

21/12/10 @ 07:49
Comment from: mr black [Visitor]
mr black

change Black for Block in the table
bd BLOCK, BLK Black device

01/08/11 @ 22:08
Comment from: davidnewcomb [Member]  

many thanks mr black

02/08/11 @ 09:07
Comment from: forum flood [Visitor]
forum flood

Thanks for putting that together :)

22/09/11 @ 21:51
Comment from: ChrisJ [Visitor]

Is there a simple way to turn off colors? (so that you see white letters on a black background and black letters on a white background). Putty defaults to a black background and xterm defaults to a white background.

In my opinion, blue-on-black and green-on-white are both ugly. : -)

23/11/11 @ 17:49
Comment from: ChrisJ [Visitor]

Ok. I see now. To turn off colors use the unalias command.
unalias ls ;

alias | egrep ls
alias l.=’ls -d .* –color=tty’
alias ll=’ls -l –color=tty’
alias ls=’ls –color=tty’

It is ok to create new aliases that are not spelled the same as the standard commands. But I feel very strongly that you should never change the behaviour of an existing command such as ls. The last thing you want is to have your script changing behaviour (breaking) based on the configuration of the user running it.

This is a great guide. Thanks for writing it.

23/11/11 @ 18:06
Comment from: Kirby Foster [Visitor]
Kirby Foster

Thanks for the easy to read howto.

12/07/12 @ 19:59
Comment from: Curtis Rueden [Visitor]
Curtis Rueden

One more color code for the list:
30 = Black

31/10/13 @ 20:18
Comment from: zss [Visitor]  

block entry ?

14/02/15 @ 12:38
Comment from: cyrille [Visitor]  

Other than color names choice (ie 33 looks like yellow and 47 like white to me eyes), this is a fu*ing well done an dcomprehensive explanation on setting up LS_COLORS :)

Here’s how I set it up in ~/.bashrc (XDG compliant if it exists):

# Enable colors for ls, etc, prefering user’s dircolors
if type -P dircolors >/dev/null ; then
if [[ -f “$XDG_HOME_CONFIG/bash/dircolors” ]] ; then
eval $(dircolors -b “$XDG_HOME_CONFIG/bash/dircolors")
elif [[ -f ~/.dircolors ]] ; then
eval $(dircolors -b ~/.dircolors)
elif [[ -f /etc/DIR_COLORS ]] ;
eval $(dircolors -b /etc/DIR_COLORS)

The following article emphasize on testing colors (nice tests) and setting usefull prompts thanks to your colors: *Bash tips: Colors and formatting* ( )

25/03/15 @ 07:57
Comment from: Kevin [Visitor]

In Ubuntu 15.10 (and perhaps in the Debian it is derived from), the setup is already in place. You just have to create the desired color scheme in your home directory as ~/.dircolors. The other locations mentioned above are not supported out of the box. The relevant stanza in the provided .bashrc is (in part):

if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)";
alias ls='ls --color=auto';

20/04/16 @ 15:34
Comment from: Rubo77 [Visitor]

add 107 = white background

10/11/17 @ 00:35
Comment from: Arc [Visitor]

Thank you for this.

I had a problem with a bright green highlight showing for the background color of directories on an NTFS drive. Changing the line in .dir_colors from:

OTHER_WRITABLE 34;42 # dir that …


OTHER_WRITABLE 94;40 # dir …

made it more bearable.

22/12/17 @ 01:36

Leave a comment

Your email address will not be revealed on this site.

Your URL will be displayed.
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)