10.3: Colored output from ls (revisited)

Oct 31, '03 08:17:00AM

Contributed by: flunkedflank

Under older versions of OS X you had to download a custom version of ls in order to get colored file listings (see this older hint). This custom version also used a helper program called dircolors which created color preferences from a .dircolorsfile.

Under Panther, this can all be done now with the built-in version of ls, and without the dircolors program. Instead of the --color flag, the built-in ls uses the -G flag or the CLICOLOR environment variable. The color preferences can be set using the LSCOLORS environment variable. For full information, browse the man page with man ls. Note the man page says that "d" is brown when used in LSCOLORS, but in fact it is yellow. Yellow is nice to use for directories when you have a black terminal background.

I use tcsh, and I have the following in my ~/.cshrc file:

setenv CLICOLOR 1
# use yellow for directories
setenv LSCOLORS dxfxcxdxbxegedabagacad

The syntax for bash would be slightly different, to go into a .bashrc file:

export CLICOLOR=1
# use yellow for directories
export LSCOLORS=dxfxcxdxbxegedabagacad

There might be more official locations to put custom shell settings (something in the Library directory?) but I'm from the Unix world so I still use .cshrc. Anyway, once you use colored ls, you will never go back!

[robg adds: I decided to run this one, even though it's also discussed in a recent hint, as that hint may have been too tcsh-specific (and too complex!) for 10.3.]

Comments (21)

Mac OS X Hints