Linux / Unix Colored Man Pages With less Command

How do I see colored man pages with standard Unix or Linux less command without installing most paging program for Unix / Linux like operating system?

You can use the less command, which is a program similar to more), but which allows backward movement in the file as well as forward movement. Edit ~/.bashrc file using a text editor such as vim / vi, enter:

How to view colored man pages in Linux

Edit the ~/.bashrc, run:
$ vi ~/.bashrc
Append the following code to get coloured manual pages with less command:

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 "$@"
}

Save and close the file. Just load your updated ~/.bashrc with the source command:
$ source ~/.bashrc
Test it:
$ man ls
$ man date
$ man 3 printf

A Note About Colored Man Pages On xterm or rxvt-unicode

If you are using xterm/uxterm or rxvt-unicode edit the ~/.Xresources or ~/.Xdefaults file, enter:
$ vi ~/.Xresources
OR
$ vi ~/.Xdefaults
Xterm user add:

*VT100.colorBDMode:     true
*VT100.colorBD:         red
*VT100.colorULMode:     true
*VT100.colorUL:         cyan

rxvt-unicode user add:

URxvt.colorIT:      #87af5f
URxvt.colorBD:      #d7d7d7
URxvt.colorUL:      #87afd7

Save and close the file. Type the following command:
$ xrdb -load ~/.Xresources
OR
$ xrdb -load ~/.Xdefaults
To view the man page of grep command, enter:
$ man grep

less command summary

Moving around:

  e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
  y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
  f  ^F  ^V  SPACE  *  Forward  one window (or N lines).
  b  ^B  ESC-v      *  Backward one window (or N lines).
  z                 *  Forward  one window (and set window to N).
  w                 *  Backward one window (and set window to N).
  ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
  d  ^D             *  Forward  one half-window (and set half-window to N).
  u  ^U             *  Backward one half-window (and set half-window to N).
  ESC-)  RightArrow *  Right one half screen width (or N positions).
  ESC-(  LeftArrow  *  Left  one half screen width (or N positions).
  ESC-}  ^RightArrow   Right to last column displayed.
  ESC-{  ^LeftArrow    Left  to first column.
  F                    Forward forever; like "tail -f".
  ESC-F                Like F but stop when search pattern is found.
  r  ^R  ^L            Repaint screen.
  R                    Repaint screen, discarding buffered input.

Commands marked with * may be preceded by a number, N.

Searching keyboard shortcuts

 
  /pattern          *  Search forward for (N-th) matching line.
  ?pattern          *  Search backward for (N-th) matching line.
  n                 *  Repeat previous search (for N-th occurrence).
  N                 *  Repeat previous search in reverse direction.
  ESC-n             *  Repeat previous search, spanning files.
  ESC-N             *  Repeat previous search, reverse dir. & spanning files.
  ESC-u                Undo (toggle) search highlighting.
  &pattern          *  Display only matching lines

Jumping around

  g  <  ESC-<       *  Go to first line in file (or line N).
  G  >  ESC->       *  Go to last line in file (or line N).
  p  %              *  Go to beginning of file (or N percent into file).
  t                 *  Go to the (N-th) next tag.
  T                 *  Go to the (N-th) previous tag.
  {  (  [           *  Find close bracket } ) ].
  }  )  ]           *  Find open bracket { ( [.
  ESC-^F <c1> <c2>  *  Find close bracket <c2>.
  ESC-^B <c1> <c2>  *  Find open bracket <c1>

See less command man page or hit the h to activate the help screen while reading man pages:
man less

Conclusion

You learned how to configure less command to display color when using the man command.

This entry is 2 of 2 in the Linux / UNIX Colorful Man Pages Tutorial series. Keep reading the rest of the series:
  1. Display Colored Man Pages in Linux and Unix
  2. Colored Man Pages With less Command

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • tangram Apr 17, 2012 @ 11:01

    Thanks for the article.

    Just tried it on my home CentOS system through SSH using Putty. It works like a charm under this conditions.
    When I get home I’ll try the suggestions under X.

    Any chances of having this working under other shells such as tcsh and zsh?

    Regards.

  • user23 May 19, 2013 @ 11:56

    Thanks,
    i was searching for that. Using most as a pagerviewer is also possible, but i was missing the ‘J’ and ‘K’ key to navigate through the page.

  • Ideophage Jul 10, 2013 @ 12:50

    /etc/conf.conf > /etc/most.conf

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum