33
7
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
33
7
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
38
Use the --human
parameter to view colored dmesg
output in a less
-like environment.
dmesg --human --color=always
Alternatively, use the following command to achieve similar results.
dmesg --color=always | less -R
Many other utilities which produce colored output (ls
, grep
, etc.) have a similar --color=always
option.
1Actually
--human
does more than just preserve color and pipe toless
: it also marks dates as e.g.[May23 00:58]
and subsequent small offsets as[ +6.046768]
instead of what would always be[121187.191521]
withless
. – Ruslan – 2017-05-23T12:56:55.680Is there a way to make this preserving of color formatting automatic for anytime I'm piping any txt based command (not just dmesg)? – mikemtnbikes – 2018-08-02T18:48:11.700
@mikemtnbikes You have to use the
--color=always
if provided by the program. A program knows if it is outputting to a pipe and can therefore decide to output color or not. – Steven – 2018-08-22T16:04:42.443