Viewing MAN pages in Color
PROBLEM DESCRIPTION or QUESTION
I'd like to see MAN pages in color, but they are only appearing in black and white.
RESOLUTION
The man program uses the PAGER program to handle the MAN page's results. Typically, the utilized PAGER is 'less' or 'more.' Both 'less' and 'more' do not handle outputs in color. Therefore, many MAN pages are printed in black and white.
To see MAN pages in color, you'll need to change the MAN code to a value that can be expressed in color. To do this, you can either:
- Change the TERMCAP code
- Use a separate PAGER program like 'most'
- Use the man2html tool
Changing TERMCAP Method
export LESS_TERMCAP_mb=$'\e[1;32m' # begin blinking export LESS_TERMCAP_md=$'\e[1;32m' # begin bold export LESS_TERMCAP_me=$'\e[0m' # end mode export LESS_TERMCAP_se=$'\e[0m' # end standout-mode export LESS_TERMCAP_so=$'\e[01;33m' # begin standout-mode export LESS_TERMCAP_ue=$'\e[0m' # end underline export LESS_TERMCAP_us=$'\e[1;4;31m' # begin underline
The color representation in the code example above is as follows:
- 31 – The second foreground color in the terminal color scheme. Usually red color is used.
- 32 – The third foreground color in the terminal color scheme. Usually green color is used.
- 33 – The fourth foreground color in the terminal color scheme. Usually yellow color is used.
The other terminal code in the above example is as follows:
- 0 – reset
- 1 – bold
- 4 – underlined
For a more detailed explanation, refer to the terminal code manual.
Most PAGER Method
# apt install most # Debian/Ubuntu # yum install most # RHEL / CentOS, Fedora # dnf install most # Recent RHEL, CentOS, Fedora
$ export PAGER=/usr/bin/most $ man cp
man2html Tool Method
$ gunzip -c $MANPATH/man1/cp.1.gz | man2html - | lynx -stdin