Pipe to less but keep the highlighting

highlightinglesspipesyntax highlighting

Is it possible to pipe output (e.g. dmesg) to a command like less (or equivalent) and keep the text highlighting used by the original command?

example: on the left dmesg | less on the right dmesg

<code>dmesg | less</code> vs <code>dmesg</code>

Best Answer

Use the --human parameter to view colored dmesg output in a less-like environment.

dmesg --human --color=always

Or use the short version:

dmesg -H

Alternatively, use the following command to achieve similar results.

dmesg --color=always | less -R

Many other utilities that produce colored output (ls, grep, etc.) have a similar --color=always option.

Related Question