3
tree go | less -R

Debian/Linux tree includes ANSI color escape sequences matching the form ESC]...m in its output.

I would like less -R --RAW-CONTROL-CHARS to output the incoming ANSI "color" sequences. I am wanting to see color in the output of less.

Instead, less says There is no R-RAW-CONTROL-CHARS option ("less --help" for help)

How can I stop less from removing ANSI color sequences from stdin?

Giacomo1968
  • 55,001
Paul
  • 103

1 Answers1

3

I believe that it is not less that is removing the color sequences, but rather tree that detects that its output is not to the console and decides to omit the sequences.

The tree man page has this option which solves the problem for me:

-C

Turn colorization on always, using built-in color defaults if the LS_COLORS environment variable is not set. Useful to colorize output to a pipe.

Use it as follows :

tree -C | less -R
harrymc
  • 480,290
  • One problem down: tree -C | less -R does relay color, but less still produces the error "There is no R-RAW-CONTROL-CHARS option ("less --help" for help) Press RETURN to continue" which requires me to press return which is annoying. – Paul May 18 '22 at 15:08
  • 1
    Is less aliased with parameters? – harrymc May 18 '22 at 15:46
  • I found the invalid --R-RAW-CONTROL-CHARS instead of --RAW-CONTROL-CHARS. Thank You. – Paul May 18 '22 at 22:39