Linux – Keep color in less after make and pipe

bashlesslinuxmakezsh

I would like to keep color in less command after using "make 2>&1" to compile some program. There are similar topics with "grep" and "ls" commands but solutions do not work with this command.

For instance,

make 2>&1 | less -R 

does not work.

Thanks for your help.

Best Answer

The simplest solution is:

unbuffer make |& less -r

This is based on the answer to Preserve colors while piping to tee

I had to "sudo apt-get install expect" to get the unbuffer command installed.

Note that the "-r" option for less tells it to display ANSI color codes, while using |& pipes in both STDOUT and STDERR.

Related Question