Notes

Coloring the Mac Terminal

Edit on GitHub

Linux
2 minutes

Adding colors to ls and tree

Enabling Colors

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

1export CLICOLOR=1
2export LSCOLORS=ExFxCxDxBxegedabagacad

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

1export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx

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

Making it permanent

You can add

1alias ls='ls -Gp'
2alias 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:

 1# COLORS
 2a  black
 3b  red
 4c  green
 5d  brown
 6e  blue
 7f  magenta
 8c  cyan
 9h  light grey
10
11# BOLD CLOLORS
12A  block black, usually shows up as dark grey
13B  bold red
14C  bold green
15D  bold brown, usually shows up as yellow
16E  bold blue
17F  bold magenta
18G  bold cyan
19H  bold light grey; looks like bright white
20
21# DEFAULT
22x  default foreground or background
placekeyforegroundbackgroundmeaning
1directoryExbold blue with default background for directories
2symlinkFxbold 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

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

adding colors to common logfiles

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

Related