SHARE
Facebook X Pinterest WhatsApp

Bash, in Color

Written By
thumbnail Juliet Kemp
Juliet Kemp
Sep 1, 2020
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



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:

Tip of the Trade: A little color on the command line makes things easier to
read.

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

thumbnail Juliet Kemp

Juliet Kemp is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.