APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > News Posts > Linux colors ls ––color command, shell ls colorization
Printer Friendly Version




News Group Posts

Linux colors


(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, 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:

--color[=WHEN]
              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

COLORS=/etc/DIR_COLORS
[ -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
fi
 

If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

1 comment




More Articles by



Click here to add your comments





Sun Mar 28 20:00:28 2010:   anonymous

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



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



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. We appreciate comments and article submissions.

Publishing your articles here

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.

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.


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


book graphic unix and linux troubleshooting guide


 I sell and support
 Kerio Mail server
pavatar.jpg

This post tagged:

       - Linux
       - Shell




Unix/Linux Consultants

Skills Tests

Guest Post Here