Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Some programs have a colored output (such as grep or emerge on my gentoo system), but if their output is piped, into less for example or into a file, the colored output is disabled.

Yet, I know less is able to display colored output, as commands such as

ccze -A < /var/log/emerge.log | less

do display colored text. So I have two questions here :

  • Is it possible to "trick" other colored output programs to keep the coloration ?
    I would like to keep colors if I do for example :

    emerge -puND world | less
  • How do these programs detect that their output is redirected ?

share|improve this question
From the emerge man page: --color < y | n > Enable or disable color output. This option will override NOCOLOR (see make.conf(5)) and may also be used to force color output when stdout is not a tty (by default, color is disabled unless stdout is a tty). – gniourf_gniourf Sep 14 '13 at 15:28
up vote 2 down vote accepted

From stackoverflow - on detecting tty:

Most commands that do print out those color codes explicitly check if stdout/stderr is a tty (using the isatty command).

From stackoverflow - on capturing colorized output:

One way to capture colorized output is with the script command. Running script will start a bash session where all of the raw output is captured to a file (named typescript by default).

See man script for more information.

share|improve this answer

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.