I practically “live” on the Linux command line and one thing that has been bugging me for so long that now I decided to do something about it. On my company’s Linux systems the ls command produces color output, which makes it easy to distinguish different file types. However, the directories are dark blue which makes it nearly impossible to see against the black background.
To fix the problem, my research took me to the LS_COLORS environment variable and a command named dircolors. The solution is to set the LS_COLORS environment variable to control how the ls command chooses its color. I can set the LS_COLORS variable manually, but there is a better way which employes the dircolors command.
The dircolors command output commands to set the LS_COLORS environment. It also output the colors in human-readable format, allowing easy modifications.
To use the dircolors, the first step is to save the current settings into a file. From the terminal, I issued one of the following commands:
dircolors -p > ~/dircolors.txt
The next step is to edit the file ~/dircolors.txt. This file’s format is easy to understand and self-documented; I had no problem finding the file that begins with “DIR” and change the color to my taste.
Next, I try out the new color scheme:
eval $( dircolors -b ~/dircolors.txt ); ls # bash shell syntax eval `dircolors -c ~/dircolors.txt`; ls # C shell syntax
After finding the color scheme I liked, I saved it to my start up file:
dircolors -b ~/dircolors.txt >> ~/.profile # bash shell dircolors -c ~/dircolors.txt >> ~/.cshrc # C shell
From this point on, I no longer have to put up with hard-to-see colors.
Solution for BSD Systems
On BSD systems, which includes the Mac OS X, the variable in question is LSCOLOR (note the lack of the underscore character). The format of this variable is different from the Linux’s LS_COLORS. The default is exfxcxdxbxegedabagacad. The value of this variable consists of pairs of characters; the first character is the code for foreground color, and the second is for background. Please consult the man page for ls on BSD for more information.
The Interactive Solution
While I like to do things the hard way to learn more about the inner-working of the OS, there is a more interactive way: point your browser here to an interactive online web application which assist you in setting the colors. After finding your desired color scheme, you still have to cut and paste it to your start up file.
Google is your friend: do a search for LSCOLORS or LS_COLORS will result in more information that you ever care to read.