Mac OS X,  Mac OS X Server,  Ubuntu,  Unix

Colorizing the Terminal

It really helps me to see different types of entries in the Terminal listed with different colors. I don’t go for listing everything that you can list as a different color though, as it starts looking a bit like a circus in Terminal when I do. If you want to colorize your terminal in Mac OS X there are two main ways to do so; both will require altering your .bash_profile (or creating if it’s not already there).

To get started, go to your home folder from within Terminal and open .bash_profile from your favorite text editor. If it doesn’t exist then the text editor should create a new file when you save it. Now that you’ve created the .bash_profile paste these two lines in there:

export CLICOLOR=1
export LSCOLORS=ExxxxxDxBxegedabxxacad

The above export can be seen as having two aspects. The first is the position. There are a total of 11 positions, with a foreground and a background being listed in that order, for each position, resulting in 22 total letters. The following represents each position, in sequence:

  1. Directory
  2. Symbolic link
  3. Socket
  4. Pipe
  5. Executable
  6. Special block
  7. Special character
  8. Executable w/ setuid set
  9. Executable w/ setgid set
  10. Directory that is writable to others w/ sticky bit
  11. Directory that is writable to others w/out sticky bit

Next, consider the colors that are used. These include:

  • a black
  • b red
  • c green
  • d brown
  • e blue
  • f magenta
  • g cyan
  • h light grey
  • x default foreground or background

Additionally, each of these colors can be used in upper case, resulting in a bold version of the same color. So if we want everything else listed with the default colors except for directories and we wanted those listed in red, we could use the following LSCOLORS line:

export LSCOLORS=ExFxCxDxBxegedabagacad

export LSCOLORS=bxxxxxxxxxxxxxxxxxxxxx

Now let’s say that we’re going to have our executables listed in blue, directories in red and everything else in the default colors:

export LSCOLORS=bxxxxxxxexxxxxxxxxxxxx

Finally, let’s say that we’re going to retain those two settings but also have the special block with a red background and black text:

export LSCOLORS=bxxxxxxxexBxxxxxxxxxxx

Additionally you can customize the colors of your prompt (and customize how it looks and what’s included. I’ll get to the prompt customization later though, as I’ve got a little football to go watch…  Favre + Vikes!