October 22, 2014
 
 
RSSRSS feed

Colorizing the Linux Command Line

A Little Color for Readability

  • August 11, 2009
  • By Juliet Kemp

Juliet Kemp

I find that a little color on the command line helps make things easier to read. ls is easy to colorize: just add the line:

alias ls='ls --color=auto'

in your ~/.bashrc (then source it or open another terminal).

You can also set color up for your manpages. The easiest way to do this is using most as a pager: Install the most package, and then type

export MANPAGER="/usr/bin/most -s"

Try looking at a man page and you'll suddenly see it in color! However, most isn't as good as less as a pager, and if you're accustomed to less you don't necessarily want to retrain your fingers to new commands. An alternative is to set up assorted termcap-related environment variables to provide colors. Add these lines to your .bashrc:

export LESS_TERMCAP_mb=$'E'01;31m'
export LESS_TERMCAP_md=$'E'01;31m'
export LESS_TERMCAP_me=$'E'0m'
export LESS_TERMCAP_se=$'E'0m'
export LESS_TERMCAP_so=$'E'01;44;33m'
export LESS_TERMCAP_ue=$'E'0m'
export LESS_TERMCAP_us=$'E'01;32m'

(with thanks to the CLUG wiki, which also has some other tips). Source your ~/.bashrc and type export MANPAGER="less" to clear the most setting (or just open a new terminal window) and take a look at a man page.

Note: not all systems automatically source ~/.bashrc on login. If you're having problems, trying manually sourcing ~/.bashrc, and if that works, add a line

source ~/.bashrc

to your ~/.bash_profile.

Finally, you can install the package grc to provide color for certain commands (check /etc/grc.conf to confirm which ones -- you can also add your own definitions here). Use it like this:

grc diff file1 file2

Although in the case of diff, a better solution may be to use vimdiff or gvimdiff, both of which provide colors by default and also puts the files side-by-side in a much easier to read format.

Follow ServerWatch on Twitter

Article courtesy of Serverwatch

Sitemap | Contact Us