Adding colors to ls and tree

Enabling Colors

Edit ~/.bash_profile or ~/.profile and add the following two lines:

export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

you can use this if you are using a black background:

export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx

LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd" will emulate the default colouring on the linux ls command.

Making it permanent

You can add

alias ls='ls -Gp'
alias tree="tree -C"

to your ~/.bash_profile to ALWAYS get colored ls and tree output.

-G enables colorized output and the -p adds a slash after each directory. the -C turns on colorization for the tree command.

Customizing Colors (Mac)

The format is as follows: LSCOLORS=ExFxCxDxBxegedabagacad

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
place key foreground background meaning
1 directory E x bold blue with default background for directories
2 symlink F x bold magenta with default background for symlinks

Note: at this point i believe that you can not specify colors based on file extensions (for example, pink for image files extension like .jpeg,.jpg,.png or brown for code file extensions like .html, .js, .php etc.) You can do that in the GNU version of ls though, so i think that one is more powerful. Plus GNU ls has a better color specifying format in the form of LS_COLORS="di=01;90:ow=01;90"

adding colors to grep matches

add the following to ~/.bash_profile

# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'

adding colors to common logfiles

brew install grc
echo 'source "`brew --prefix grc`/etc/grc.bashrc"' >> ~/.bash_profile   
source ~/.bash_profile