How to View Colored Man Pages in Linux

[‘

n

In Unix-like operating systems, a man page (in full manual page) is a documentation for a terminal-based program/tool/utility (commonly known as a command). It contains the name of the command, syntax for using it, a description, options available, author, copyright, related commands etc.

n

Read Also: ccat – Show ‘cat Command’ Output with Syntax Highlighting or Colorizing

n

You can read the manual page for a Linux command as follows; this will display the man page for the df command:

n

$ man df rn

n

df Command Man Page
df Command Man Page

n

By default, the man program normally uses a terminal pager program such as more or less to format its output, and the default view is normally in white color for every kind of text (bold, underlined etc..).

n

You can make some tweaks to your ~/.bashrc file to get nicely colored man pages by specifying a color scheme using various LESS_TERMCAP variables.

n

$ vi ~/.bashrcrn

n

Add following color scheme variables.

n

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

n

Following are the color codes that we used in the above configuration.

n

    n

  • 31 – red
  • n

  • 32 – green
  • n

  • 33 – yellow
  • n

n

And here are the meanings of the escape codes used in the above configuration.

n

    n

  • 0 – reset/normal
  • n

  • 1 – bold
  • n

  • 4 – underlined
  • n

n

You can additionally reset your terminal by typing reset or even start up another shell. Now when you try to view a man page df command, it should look like this, nicer than the default view.

n

Colored Man Page
Colored Man Page

n

Alternatively, you can use the MOST paging program, which works on Unix-like operating systems and supports multiple windows and can scroll left and right.

n

$ sudo apt install mosttt#Debian/Ubuntu rn# yum install mosttt#RHEL/CentOSrn# dnf install mosttt#Fedora 22+rn

n

Next, add the line below in your ~/.bashrc file, then source the file like before and possibly reset your terminal.

n

export PAGER="most"rn

n

Most Paging Program for Linux
Most Paging Program for Linux

n

Read Also: How to Customize Bash Colors and Content in Linux Terminal Prompt

n

In this article, we showed you how to display beautifully colored man pages in Linux. To send us any queries or share any useful Linux shell tips/tricks, use the comment section below.

n

‘]