Enabling Terminal’s directory and file color highlighting in Mac OS X

By default Mac OS X’s Terminal application uses the Bash shell (Bourne Again SHell) but doesn’t have directory and file color highlighting enabled to indicate resource types and permissions settings.

mac-terminal-directory-file-highlighting

Enabling directory and file color highlighting requires that you open (or create) ~/.bash_profile in your favourite text editor, add these contents:

export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

… save the file and open a new Terminal window (shell session). Any variant of the “ls” command:

ls
ls -l
ls -la
ls -lah

… will then display its output in color.

More details on the LSCOLORS variable can be found by looking at the man page for “ls“:

man ls

LSCOLORS needs 11 sets of letters indicating foreground and background colors:

  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

The possible letters to use are:

a  black
b  red
c  green
d  brown
e  blue
f  magenta
c  cyan
h  light grey
A  block 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

By referencing these values, the LSCOLORS variable setting mentioned above translates to:

Bold blue with default background for directories, bold magenta with default background for symbolic links, bold green with default background for sockets, etc.

 

Related posts:

  1. Checking directory sizes on a Bash command line
  2. Exporting your iPhone’s SMS Message Database to a CSV file
  3. Displaying a text-based file and folder tree on the command line
  4. Bash Script to split a single CSV file into multiple files with headers
  5. Configure a Quake-style dropdown Terminal in Mac OS X
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

17 Responses to “Enabling Terminal’s directory and file color highlighting in Mac OS X”

  1. Yo, thanks for this explanation. There are a few other blogs out there that try to explain the color scheme, but none of them cover what the line “ExFxCxDxBxegedabagacad” means, or how to change the colors of particular items. Thanks again, you saved a newbie some hard work.

  2. Sure thing! Let me know if you get stuck with anything else. :)

  3. Thanks, and thank you for the link! Do you use both Mac OS X and Linux, or just one of them?

  4. Indeed an awesome post. Works like a charm, thanks.

  5. Thanks, quick fix. I always set up the colours in the shell but the colour values always differ from one env/shell to the next.

  6. Thanks. Worked perfectly!

  7. Thanks Willem! You definitely saved me some time!

    It never occurred to me to check the man pages for coloring. I’m relatively new to Macs, and I noticed that the man pages on the Macs appear to be more straightforward with these particular instructions compared to a system running RHEL5…

  8. Hey Jason

    Sure! OS X is based on BSD and inherited many of its man pages from there.

  9. yes, thanks very helpfull, but I would have an other issue related to this:
    there’s a way even to chose the colors for other file extensions:
    i would like to have the .pdf in a color and the .txt or .tex in one other. someone know if this is possible?
    thanks a lot
    laura

  10. Is there a way I can use colors to distinguish between file extensions? For instance, I use C and Matlab extensively, and it would be nice if my .c and .m files were shown in two different colors.
    Thanks!

  11. Thanks a lot!!! Works like a charm! :-D

  12. Awesome! Thanks for the simple explanation.

  13. Thanks a lot, it just works!!!

Trackbacks/Pingbacks

  1. bash settings on Mac Snow Leopard | semioticpixels scratch pad - 21 Jan 2010

    [...] adding file and directory colors to Terminal VN:F [1.8.1_1037]please wait…Rating: 0.0/10 (0 votes cast)VN:F [1.8.1_1037]Rating: 0 (from 0 votes) [...]

  2. Michael Dean (anothercynic) « Enabling Terminal’s directory and file color highlighting in ... « Chat Catcher - 06 Jun 2010

    [...] 2010-06-06T09:21:31 Enabled ls file type colors in Mac OS X: [link to post] [...]

Afrigator