How to View Colored Man Pages in Linux?

LinuxOperating SystemSoftware & Coding

The man pages are important reference pages for any Unix user. But their look and feel is very boring because it is just lines of text with some punctuations. In this article we will see how the different parts of the man pages can be coloured and highlighted. That will make it very easy to follow the instructions in the man pages.

Using most

The most command can be used to display the colour man pages but first we have to install it and then add to our bash profile so that it becomes available in the environment. The below command shows how to install most.

sudo apt install most

Once added we, can append the value into the .bashrc file, so that the profile gets updated and the variable is available in the environment. We refresh the profile using the source command.

export PAGER="most"
# Sourve the .profile file.
$ source ~/.profile

Next we run the below command to see how coloured man pages appear when we query the man pages with some command.

Example

Man cp

Output

using the TERMCAP variable

Termcap stands for terminal capability database. Located in /etc/termcap, it is an ASCII file 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. We add the below code to .bashrc file.

Example

export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'

Output

Next we runt the ls command and get the colored output as below.

raja
Published on 14-Feb-2020 10:55:06
Advertisements