2 Easy Ways To Get Color Man Pages In Linux

Are you frequent visitor to man page (stands for manual pages)? the default view hurt your eyes? don’t worry, this article will help you to read man page with colors. Man pages by default use less command as a pager.

I was sticking with man page (stands for manual pages) most of the time to know more about command usage when writing a article, especially in the night time i got pissed off very often while reading a man page with default view. I know how much painful it is because i have struggled a lot.

Colored man page greatly improve your reading habit. This can be achieved in two ways, either by adding LESS_TERMCAP environment variables on your .bashrc file or by installing most utility.

Method-1 : Using Most Command

MOST is a powerful paging program for Linux system that displays file contents on page wise. It display status line on the scree which includes file name, current line number, and the percentage of the file so far displayed.

Suggested Read :
(#) Cheat – A Collection Of Practical Linux Command Examples

How to Install Most in Linux

Most is available in most of the distribution official repository, so get it installed from package manager.

For Debian/Ubuntu, use apt-get command or apt command to install most.

$ sudo apt install most

For RHEL/CentOS, use YUM Command to install most.

$ sudo yum install most

For Fedora, use DNF Command to install most.

$ sudo dnf install most

For Arch Linux, use Pacman Command to install most.

$ sudo pacman -S most

For openSUSE, use Zypper Command to install most.

$ sudo pacman -S most

Add below environment variable into .bashrc file.

$ export PAGER="most"
$ export PAGER="/usr/bin/most -s"

Run the following command to take this effect.

# source ~/.bashrc

Now, open any command man page which will show colored output.

Method-2 : Using less command

Less is a free, open-source file pager. less command allows you to quickly view the file contents on screen from top to bottom using UP & DOWN arrow keys or Page UP & Page Down button.

Termcap stands for terminal capability database. /etc/termcap is an ASCII file (the database master) that lists the capabilities of many different types of terminals.

Programs can read termcap to find the particular escape codes needed to control the visual attributes of the terminal actually in use.

Just Append the below code on your .bashrc file to get colored man pages.

export LESS_TERMCAP_mb=$'\E[1;31m'     # begin bold
export LESS_TERMCAP_md=$'\E[1;36m'     # begin blink
export LESS_TERMCAP_me=$'\E[0m'        # reset bold/blink
export LESS_TERMCAP_so=$'\E[01;44;33m' # begin reverse video
export LESS_TERMCAP_se=$'\E[0m'        # reset reverse video
export LESS_TERMCAP_us=$'\E[1;32m'     # begin underline
export LESS_TERMCAP_ue=$'\E[0m'        # reset underline
export GROFF_NO_SGR=1                  # for konsole and gnome-terminal

Run the following command to take this effect.

# source ~/.bashrc

Now, open any command man page which will show colored output.

Reference : wiki.archlinux.org

Prakash Subramanian

Prakash Subramanian is a Linux lover and has 3.5+ years of experience in linux server administration with major Linux distribution such as (RHEL, CentOS, Ubuntu). He is currently working as a Senior L2 Linux Server administrator.

You may also like...