The man page refers to the manual pages.
Do you frequently visit man pages? Does the default vision hurt your eyes?
If yes, then don’t worry, this article will help you read the man page with colors.
By default, man pages use the less command as a pager.
Most of the time I was sticking with man pages to learn more about any command use when writing an article.
I struggled a lot, especially at night, when reading a man page with the default view.I know how painful it is because I have faced lot of trouble.
Colored man pages greatly improve your reading habits.
If you are looking for an interactive cheatsheet in the Linux command line, navigate to the cheat command.
This can be achieved in two ways by adding LESS_TERMCAP
environment variables to your .bashrc
file or installing the most
application.
Method-1: How to get colored Man pages on Linux using the Most Command
MOST command is a powerful paging program for a Linux system that displays file contents page-wise.
This will display the status line on the screen, including the file name, the current line number, and the percentage of the file displayed so far.
How to install Most application in Linux
Most application is available in the official repository, so you can easily install it with the help of the distribution 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
Once you have installed the most application, add the following environment variable to the .bashrc
file.
$ export PAGER="most" or $ export PAGER="/usr/bin/most -s"
Run the following command to make this change effective.
# source ~/.bashrc
Yes, you have done everything, and if you open any of the commands in your terminal, it will display a color output like the one below.
Method-2: How to get colored Man Pages in Linux using the TERMCAP variable
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.
Append the codes below to your .bashrc
file to get colored man pages.
$ vi ~/.bashrc export LESS=-R export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink export LESS_TERMCAP_md=$'\E[1;36m' # begin bold 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
Run the following command to take this change effect.
$ source ~/.bashrc
Alternatively, you can use the following codes for bash or zsh.
$ vi ~/.bashrc man() { LESS_TERMCAP_md=$'\e[01;31m' \ LESS_TERMCAP_me=$'\e[0m' \ LESS_TERMCAP_se=$'\e[0m' \ LESS_TERMCAP_so=$'\e[01;44;33m' \ LESS_TERMCAP_ue=$'\e[0m' \ LESS_TERMCAP_us=$'\e[01;32m' \ command man "$@" }
Run the following command to take this change effect.
$ source ~/.bashrc
For Fish shell, use the following codes.
$ vi ~/.config/fish/config.fish set -xU LESS_TERMCAP_md (printf "\e[01;31m") set -xU LESS_TERMCAP_me (printf "\e[0m") set -xU LESS_TERMCAP_se (printf "\e[0m") set -xU LESS_TERMCAP_so (printf "\e[01;44;33m") set -xU LESS_TERMCAP_ue (printf "\e[0m") set -xU LESS_TERMCAP_us (printf "\e[01;32m")
Run the following command to make the changes take effect.
$ source ~/.config/fish/config.fish
Now, if you open any of the commands in your terminal, it will display a colored output like the one below.
Reference : wiki.archlinux.org