Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I look at a man page in my 'console' (not an xterm) I see some coloration, but I don't get this in my xterm's (e.g. konsole) is there any way I can enable this? hopefully a fairly simple solution?

share|improve this question
up vote 49 down vote accepted

You need to use the termcap(5) feature. The man page on some Unices says this tool is obsolete and to use terminfo, but it's still available on others (and terminfo is more complicated).

More importantly, less uses termcap.

Setting colors for less

I do the following so that less and man (which uses less) will have color:

$ cat ~/.LESS_TERMCAP 
export LESS_TERMCAP_mb=$(tput bold; tput setaf 2) # green
export LESS_TERMCAP_md=$(tput bold; tput setaf 6) # cyan
export LESS_TERMCAP_me=$(tput sgr0)
export LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4) # yellow on blue
export LESS_TERMCAP_se=$(tput rmso; tput sgr0)
export LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7) # white
export LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
export LESS_TERMCAP_mr=$(tput rev)
export LESS_TERMCAP_mh=$(tput dim)
export LESS_TERMCAP_ZN=$(tput ssubm)
export LESS_TERMCAP_ZV=$(tput rsubm)
export LESS_TERMCAP_ZO=$(tput ssupm)
export LESS_TERMCAP_ZW=$(tput rsupm)

And then in my ~/.bashrc, I do this:

# Get color support for 'less'

# Use colors for less, man, etc.
[[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP

NOTE: See Documentation on LESS_TERMCAP_* variables? for how this works.

The final result

    ss of man page

share|improve this answer
I believe the reason this works the way it does, is because 'console' translates 'underline' into colour, where-as X11 stuff supports underlines. You can test this theory by typing echo -e "\e[04mhello world\e[0m" in both the console and your X11 terminal and seeing the difference. So this above hack abuses termcap to lie to LESS about what codes it needs to emit for bold/underline and forces it to produce colour escape codes instead. – Kent Fredric Feb 15 '11 at 12:03
Indeed, the translation of underline into blue has historic reasons, going back to the text modes of the original PC graphics adapters MDA and CGA (actually the CGA text modes are still available to date). Those graphics adapters stored two bytes per character: One holding the ASCII code, one holding the attributes. The MDA interpreted the attribute byte as combinations of underline, bright, blinking and inverse, while the CGA interpreted that byte as foreground and background colour. And it happened that the MDA attribute for underline equalled the CGA attribute for blue on black. – celtschk May 8 '14 at 18:39
This doesn't work in Konsole or Gnome-terminal. I set them, and the only colour change is for the cursor and the status page. I turns out I need: export GROFF_NO_SGR=1. – CMCDragonkai May 4 at 7:11
Well, this used to work in Gnome Terminal, but it's been a while since I wrong these instructions so it's possible that something has changed. – Stefan Lasiewski May 4 at 17:11

You can solve this issue by using a different pager, for example most. man will actually use the program specified in the PAGER environment variable. From the man(1) man page:


If $MANPAGER or $PAGER is set ($MANPAGER is used in preference), its value is used as the name of the program used to display the manual page. By default, pager -s is used.

The value may be a simple command name or a command with arguments, and may use shell quoting (backslashes, single quotes, or double quotes).

It may not use pipes to connect multiple commands; if you need that, use a wrapper script, which may take the file to display either as an argument or on standard input.

If most is installed on your system, try this, before launching man:

export PAGER=most
share|improve this answer
most should be installed, for this to work. – enzotib Sep 14 '11 at 7:41

I think this might be helpful.


$ mkdir ~/.terminfo/ && cd ~/.terminfo

Now get the terminfo description:

$ wget http://nion.modprobe.de/mostlike.txt

Now compile it using tic (the terminfo entry-description compiler):

$ tic mostlike.txt

(You may want to delete the mostlike.txt file after compiling.)

And then just define an alias in the *rc file of your favorite shell.

$ alias man="TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man"

If you want to modify the terminfo file, use infocmp mostlike to get the content of it later.

share|improve this answer
It helps if you summarize the source here, so people can see what it says without having to click through (and in case the site ever goes down) – Michael Mrozek Aug 10 '10 at 20:57
Please provide answers, not just links to answers. It's very good to provide links which support your answer, however. Imagine I was Googling for this question--- a good answer at StackExchange will quickly find it's way to the first page of results. – Stefan Lasiewski Aug 10 '10 at 21:27
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – manatwork Nov 7 '13 at 14:21
The link is dead. – farzan Jul 5 at 10:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.