You can display colored man pages in Linux and Unix by using the GROFF_NO_SGR
environment variable and piping the output of the man
command through a pager, such as less
.
Here’s an example of how to display color man pages in a Linux or Unix system:
export GROFF_NO_SGR=1
man <command> | less -R
Where <command>
is the name of the command you want to view the man page for.
In this example, we’re setting the GROFF_NO_SGR
environment variable to 1
, which tells the groff
text formatting system not to use the SGR (Select Graphic Rendition) control sequences for text formatting. This allows the output of man
to be displayed with color in the pager.
We’re then piping the output of the man
command through less
, with the -R
option, which tells less
to display ANSI escape sequences as-is, allowing it to display the output with color.
You can also add this line to your shell profile file (e.g., ~/.bashrc
, ~/.bash_profile
, or ~/.zshrc
) to make the change permanent.