I get colored tree using tree -C but when I pipe it to less I get results like this:

tree public/ -C | less

enter image description here

How can I have colors in less in this case?


You want the -R switch to less.

From the less man page:

-R or --RAW-CONTROL-CHARS Like -r, but only ANSI "color" escape sequences are output in raw" form. Unlike -r, the screen appearance is maintained correctly in most cases. ANSI "color" escape sequences are sequences of the form:

            ESC [ ... m

So you need

tree -C public/ | less -R
  • The -r switch works for more too. – Ed L Sep 12 '13 at 0:49
  • @EdL I never said it doesn't. – Joseph R. Sep 12 '13 at 1:03
  • 3
    The question's title asked for "less" or "more", so I thought I'd just note that. – Ed L Sep 12 '13 at 1:04

Passing -r to less will tell it to pass through control characters and escape sequences unmolested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.