Adding colorized ls output to the Terminal in Mac OS X is a good way to make navigating around the command line a bit easier on the eyes.
We’ll cover a customizable setting, and you can get a preview of color ls output by typing “ls -G” at the command line. The preview with ls -G will depend on the Terminals color settings and won’t necessarily represent the colors shown below, however.
Open Terminal and type: nano .bash_profile
Use the arrow keys to navigate to the bottom of the document and paste in either of the blocks of text below, depending on the terminals appearance (see man entry below for further customizations)
Colors for Dark Terminal Themes:
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
Colors for Light Terminal Themes:
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
After the strings are pasted into .bash_profile confirm that it looks something like this in nano:
Hit Control+O to save and open a new Terminal window
Type "ls" or "ls -la" to confirm the colorized output
This will work with Mac OS X 10.6, OS X 10.7, and OS X 10.8, as long as you are using the bash shell. If you aren't certain what shell you are using, look in the Terminal window titlebar for "bash", or you can check with the following command:
echo $SHELL
The output will be "/bin/bash" if it's bash, and something else if not.
Don't forget that you can also change the appearance of Terminal windows instantly and change the Terminal wallpaper too.
Customizing LSCOLORS Manually
If the above color choices weren't doing it for you, you can set whatever you want. Here's the manual page on LSCOLORS if you want to give it a shot. The default is "exfxcxdxbxegedabagacad" but clearing out the .bash_profile color entry will remove any hideous color combinations too.
LSCOLORS The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.
The color designators are as follows:
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.
The order of the attributes are as follows:
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.
Hit Control+O to save and open a new Terminal window
Type "ls" or "ls -la" to confirm the colorized output
This will work with Mac OS X 10.6, OS X 10.7, and OS X 10.8, as long as you are using the bash shell. If you aren't certain what shell you are using, look in the Terminal window titlebar for "bash", or you can check with the following command:
echo $SHELL
The output will be "/bin/bash" if it's bash, and something else if not.
Don't forget that you can also change the appearance of Terminal windows instantly and change the Terminal wallpaper too.
Customizing LSCOLORS Manually
If the above color choices weren't doing it for you, you can set whatever you want. Here's the manual page on LSCOLORS if you want to give it a shot. The default is "exfxcxdxbxegedabagacad" but clearing out the .bash_profile color entry will remove any hideous color combinations too.
LSCOLORS The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.
The color designators are as follows:
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.
The order of the attributes are as follows:
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.
No comments:
Post a Comment