Open In App

How to View Colored Man Pages in Linux?

Last Updated : 11 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Man pages or simply manual pages are the documentation that is available with every command-line tool or application present to us in a Linux System. These types of documentation include topics from command-line tools, system calls, programs, and even abstract concepts. 

To read a man page simply type

man <package>

How to View Colored Man Pages in Linux

Man pages are usually monotonous(as evident from the image above), users usually avoid reading documentation simply because they lack the readability appeal to the users. When we make notes we used to highlight an important point and heading same can be done to man pages by selective color highlighting of text. To make this documentation appeal to the user we can simply add such kind of visuals effects to these man pages.

Following are some ways to view attractive colorful Man Pages:

1. Through tweaks to .bashrc:

By making changes to the .bashrc file we can have a nice color scheme for our man pages. We can specify the individual color scheme by specifying them through the LESS_TERMCAP variables inside our .bashrc profile. Termcap variable is from a library that is used by Less to access the terminal.

To tweak those changes follow these steps:

1. Open it inside an editor. We will use nano for it.

sudo nano ~/.bashrc

2. Then we will add the listed color scheme variable. These color codes are according to three values of red (31), green(32), and yellow(33). Colors along with the escape codes with values of reset/normal (0), bold (1), and underlined (4) give a nice format and colorization to the man pages.

export LESS_TERMCAP_mb=$'\e[01;31m'       # begin blinking
export LESS_TERMCAP_md=$'\e[01;37m'       # begin bold
export LESS_TERMCAP_me=$'\e[0m'           # end all mode like so, us, mb, md, mr
export LESS_TERMCAP_se=$'\e[0m'           # end standout-mode
export LESS_TERMCAP_so=$'\e[45;93m'       # start standout mode
export LESS_TERMCAP_ue=$'\e[0m'           # end underline
export LESS_TERMCAP_us=$'\e[4;93m'        # start underlining

How to View Colored Man Pages in Linux

Note: To have this colorization effect only on man pages and not all the programs using LESS, we can enclose all the above code in a shell function that will be named as a man. Inside the function call once the color code values are set for us, then it will also call the real man program.

man() {
        LESS_TERMCAP_mb=$'\e[01;31m'
        LESS_TERMCAP_md=$'\e[01;31m' \
        LESS_TERMCAP_me=$'\e[0m' \
        LESS_TERMCAP_se=$'\e[0m' \
        LESS_TERMCAP_so=$'\e[45;93m' \
        LESS_TERMCAP_ue=$'\e[0m' \
        LESS_TERMCAP_us=$'\e[4;93m' \
    
        command man "$@"
}

How to View Colored Man Pages in Linux

3. Activate the file with the source command.

source ~/.bashrc

How to View Colored Man Pages in Linux

Now, on viewing the same man page of printf we can see selective options are getting highlighted and colored. This helps us in identifying necessary options and flags associated with the man of printf.

The written above code is an ANSI color sequence which could be understood by these syntax:

# Taking a simpler example 
export LESS_TERMCAP_mb=$'\e[1;32m'
  • The $’xxxx’ means interpret backslash-escaped characters like \e or \n
  • \e is the escape character (ASCII 27 decimal)
  • 1 is “bold”
  • ; delimits colors
  • 32 is “green”
  • m is the end of the color sequence

You can make more such combinations by referencing this Wikipedia Article on ANSI escape sequence.

2. Using MOST Pager:

Start by installing the most using terminal.

sudo apt install most

How to View Colored Man Pages in Linux

Now add the MOST as the default pager add it to the .bashrc profile.

sudo nano ~/.bashrc

Add the following line to the profile

export PAGER="most"

How to View Colored Man Pages in Linux

Conclusion:

With these two options, we are not just making our documents pretty! With these customizations, it’s easier to scroll through long man pages. The readability improves significantly and it’s now difficult to miss an important piece of information. Now, options and parameters are highlighted for you, and much easier for you to spot them.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads