Linux / Unix: Colored Man Pages With less Command

by on April 9, 2012 · 5 comments· LAST UPDATED April 9, 2012

in , ,

How do I see colored man pages with standard Unix or Linux less command without installing most paging program for Unix / Linux like oses?

You can use less command, which is a program similar to more), but which allows backward movement in the file as well as forward movement. Edit ~/.bashrc file using a text editor such as vim / vi, enter:
$ vi ~/.bashrc
Append the following code to get coloured manual pages with less command:

 
man() {
	env \
		LESS_TERMCAP_mb=$(printf "\e[1;31m") \
		LESS_TERMCAP_md=$(printf "\e[1;31m") \
		LESS_TERMCAP_me=$(printf "\e[0m") \
		LESS_TERMCAP_se=$(printf "\e[0m") \
		LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
		LESS_TERMCAP_ue=$(printf "\e[0m") \
		LESS_TERMCAP_us=$(printf "\e[1;32m") \
			man "$@"
}
 

(Source: Man page from the Arch Linux wiki)

Save and close the file.

A Note About Colored Man Pages On xterm or rxvt-unicode

If you are using xterm/uxterm or rxvt-unicode edit the ~/.Xresources or ~/.Xdefaults file, enter:
$ vi ~/.Xresources
OR
$ vi ~/.Xdefaults
Xterm user add:

 
*VT100.colorBDMode:     true
*VT100.colorBD:         red
*VT100.colorULMode:     true
*VT100.colorUL:         cyan
 

rxvt-unicode user add:

 
URxvt.colorIT:      #87af5f
URxvt.colorBD:      #d7d7d7
URxvt.colorUL:      #87afd7
 

Save and close the file. Type the following command:
$ xrdb -load ~/.Xresources
OR
$ xrdb -load ~/.Xdefaults
To view the man page of grep command, enter:
$ man grep
Sample outputs:

Configure Less To Display Colored Man Page under Linux / Unix / Apple OS X

Fig.01: Colored man page

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!
This entry is 2 of 2 in the Linux / UNIX Colorful Man Pages Tutorial series. Keep reading the rest of the series:
  1. Unix / Linux: Display Color Man Pages
  2. Linux / Unix: Colored Man Pages With less Command

{ 5 comments… read them below or add one }

1 tangram April 17, 2012 at 11:01 am

Thanks for the article.

Just tried it on my home CentOS system through SSH using Putty. It works like a charm under this conditions.
When I get home I’ll try the suggestions under X.

Any chances of having this working under other shells such as tcsh and zsh?

Regards.

Reply

2 user23 May 19, 2013 at 11:56 am

Thanks,
i was searching for that. Using most as a pagerviewer is also possible, but i was missing the ‘J’ and ‘K’ key to navigate through the page.

Reply

3 Ideophage July 9, 2013 at 10:57 pm
4 Ideophage July 10, 2013 at 12:49 pm

Actually, you can do that by editing (or creating) /etc/conf.conf: https://wiki.archlinux.org/index.php/Man_Page#Using_most_.28Not_recommended.29

Reply

5 Ideophage July 10, 2013 at 12:50 pm

/etc/conf.conf > /etc/most.conf

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: