APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Linux shell colors; shell ls colorization

(This is an update and expansion of an earlier post on the same subject)

Personally, I don't like colors in my shell. I think it would be fine as an option, but to have it as the default offends me and many other old Unix hands.

You can shut off command line colorizing by editing /etc/DIR_COLORS and changing "COLOR tty" to "COLOR none" or (less drastically) by removing the "TERM ansi" line from the same file (which removes colorization for ansi but doesn't affect console use).

The shell DEFINITELY shouldn't be attempting colors when the TERM is not "linux". This just makes things worse. A common result is dark blue lettering on a black background - almost impossible to read.

If you hate vi (vim) colorization as I do, see Controlling Linux colors in vi (vim).

A more typical response advises you to edit .dir_colors. That's fine if you are regularly vising this machine, but for tech support folk, you are often coming in to use someone else's account temporarily, and you wouldn't do that, so resetting "LS_COLORS" would seem to make more sense. Unfortunately, that does nothing because the usual reason is that "ls" has been aliased. The best fix is to change the alias to 'color=never"' or to remember to use /bin/ls (which bypasses shell aliases).

(Another reason to avoid colorization is explained at ls -color considered harmful which explains why colorized "ls" may hang when a text version would not.)

If you LIKE colors and simply find the default choices awful, you can edit ~/.dircolors (if it doesn't exist you can create it with:

dircolors -p > ~/.dir_colors

Your .bashrc might then have something like:

eval `dircolors ~/.dir_colors`
alias ls="ls --color=auto"

My "man" and"info" pages for "ls" only give 3 options for --color:

              control  whether  color is used to distinguish file types.  
              WHEN may be 'never', 'always', or 'auto'

However, "color=tty" also works. That 'tty' colorizes output to ttys, but not pipes (where you likely definitely do not want that junk!)

See man/info dircolors (though neither tells you much - your /etc/dir_colors or /etc/DIR_COLORS file may tell you more).

The actual setup of colorization is more involved. On this Linux system, that's handled by /etc/profile.d/colorls.sh (sourced from /etc/profile).

# color-ls initialization

alias ll='ls -l' 2>/dev/null
alias l.='ls -d .*' 2>/dev/null

[ -e "/etc/DIR_COLORS.$TERM" ] && COLORS="/etc/DIR_COLORS.$TERM"
[ -e "$HOME/.dircolors" ] && COLORS="$HOME/.dircolors"
[ -e "$HOME/.dir_colors" ] && COLORS="$HOME/.dir_colors"
[ -e "$HOME/.dircolors.$TERM" ] && COLORS="$HOME/.dircolors.$TERM"
[ -e "$HOME/.dir_colors.$TERM" ] && COLORS="$HOME/.dir_colors.$TERM"
[ -e "$COLORS" ] || return

eval `dircolors --sh "$COLORS" 2>/dev/null`
[ -z "$LS_COLORS" ] && return

if ! egrep -qi "^COLOR.*none" $COLORS >/dev/null 2>/dev/null ; then
	alias ll='ls -l --color=tty' 2>/dev/null
	alias l.='ls -d .* --color=tty' 2>/dev/null
	alias ls='ls --color=tty' 2>/dev/null

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Linux colors ls ––color command, shell ls colorization


More Articles by

Find me on Google+

Click here to add your comments
- no registration needed!

Sun Mar 28 20:00:28 2010: 8290   anonymous


Well, I for one much prefer using colorized output. Keeps my mood up, especially during troubleshooting.

Sat Mar 3 14:59:57 2012: 10699   anonymous


dircolors is fine, but the hard part is when I take my dircolors to another machine, they look completely different! The 036 "cyan" on one machine looks totally different from the 036 "cyan" of another machine, even using the same monitor. Ideas on how to overcome that would be helpful.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments

If you want a picture to show with your comment, go get a Gravatar
Kerio Samepage

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Jump to Comments

Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

This post tagged:

       - Linux

       - Shell

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!

book graphic unix and linux troubleshooting guide

Buy Kerio from a dealer who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals