You are here

Terminal Color

Error message

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).

Sure, the green-on-green look a timeless classic. But sometimes, it's nice to have more than one color. This tutorial describes how to get colors in your terminal environment.

Terminal Type

The first requirement is that your terminal supports colors. I'm assuming that you're not running an ACTUAL vt100, but a software terminal application like Apple's built-in terminal, or perhaps iTerm (my personal favorite).

iTerm allows you to choose from a variety of terminal types including vt100, xterm, and ANSI among others. For this tutorial to work, you need to be using an ANSI terminal. vt100 doesn't support color, and Xterm is a completely different animal.

CLICOLOR

First off, color must be enabled with the CLICOLOR environment variable. The LSCOLORS variable is a string containing a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.

LSCOLORS

LSCOLORS is a shell environment variable describing which colors to use for different types of files displayed by the "ls" command.

Example

A good place to put these set these two environment variables is in your .bash_profile (or .tcshrc if using the c-shell). First an example followed by an explanation:

export CLICOLOR=1
export LSCOLORS=exfxcxdxbxegedabagacad

Color Designators

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.

Order of File Attributes

  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 default is "exfxcxdxbxegedabagacad", i.e. blue foreground and default background for regular directories, black foreground and red background for setuid executables, etc.