How to Get Color Man Pages on CentOS/RHEL/Ubuntu Linux

This post will guide you how to get color man pages of Linux command in bash shell. How to get some nicely colored man pages under Linux operating system.

Get Colored Man Pages Using Most Command


You can use a most tool that is a powerful program for Linux system that displays file contents on page wise. and it display status line on the screen which includes file name, current line number, and the percentage of the file so far displayed.

Install Most Tool

For Ubuntu/Debian Linux

If you are using Ubuntu/Debian Linux, you can use the apt-get command to install the most package, just type the following command:

$ sudo apt-get install most

Outputs:

devops@devops-osetc:~$ sudo apt-get install most
sudo: unable to resolve host devops-osetc
[sudo] password for devops:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libtinfo-dev
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
most
0 upgraded, 1 newly installed, 0 to remove and 598 not upgraded.
Need to get 42.6 kB of archives.
After this operation, 117 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 most amd64 5.0.0a-2.3+deb8u1build0.16.04.1 [42.6 kB]
Fetched 42.6 kB in 1s (36.3 kB/s)
Selecting previously unselected package most.
(Reading database ... 178950 files and directories currently installed.)
Preparing to unpack .../most_5.0.0a-2.3+deb8u1build0.16.04.1_amd64.deb ...
Unpacking most (5.0.0a-2.3+deb8u1build0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up most (5.0.0a-2.3+deb8u1build0.16.04.1) ...

For CentOS/RHEL Linux

If you are using CentOS/RHEL/ORACLE Linux, you can use the yum command to install most package, type:

$ sudo yum install most

Outputs:

[root@osetc_test ~]# yum install most
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
epel/metalink | 17 kB 00:00
* base: mirrors.sonic.net
* epel: mirror.sjc02.svwh.net
* extras: mirror.keystealth.org
* updates: mirror.sjc02.svwh.net
base | 3.7 kB 00:00
epel | 3.2 kB 00:00
epel/primary | 3.2 MB 00:00
epel 12497/12497
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package most.x86_64 0:5.0.0-14.a.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================================
Installing:
most x86_64 5.0.0-14.a.1.el6 epel 54 k

Transaction Summary
==========================================================================================================================================================================
Install 1 Package(s)

Total download size: 54 k
Installed size: 102 k
Is this ok [y/N]: y
Downloading Packages:
most-5.0.0-14.a.1.el6.x86_64.rpm | 54 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : most-5.0.0-14.a.1.el6.x86_64 1/1
Verifying : most-5.0.0-14.a.1.el6.x86_64 1/1

Installed:
most.x86_64 0:5.0.0-14.a.1.el6

Complete!

For Fedora Linux

You can use the DNF command to install most package, type:

$ sudo dnf install most

For Arch Linux

If you are using Arch Linux, you can use the Pacman command to install most package, type:

$ sudo pacman -S most

For OpenSUSE Linux

If you are using the OpenSUSE Linux, you can use the Zypper command to install most tool, type:

# zypper install most

For FreeBSD Unix

If you are using the FreeBSD Unix, and you can use the pkg command to install most, type:

# pkg install most

Using Most Command

After installed most command on your Linux system, you should add the following lines into .bashrc file to set environment variable.

export PAGER="most"

Or

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

Save and close the file. and execute the below command to take this command effect.

# source .bashrc

Then you can try to run a man command to see if the man page has been colored.

# man

color man page1

Get Colored Man Pages Using Less Command


There is another way to get colored man pages and you can use the less command that is a free, open-source file pager. and you can use this command to view the file contents on screen from top to buttom.

You just need to append the following line into the .bashrc file which is a hidden file located in your home directory which gets read each time a new bash instance launched. and the new bash shell will read all the commands found in this file and executes them.

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

Then you need to run source command to make the newly variable to take effect.

$ source .bashrc

Trying to run one man command to check if you get the colored man page:

# man ls

color man page2

You might also like:

Sidebar



back to top