tree
and ls
can distinct file types by coloring filenames differently.
tree
and ls
often output a long list of files (including directories), so I pipe the stdout output to less
.
But less
doesn't preserve the colors. How can we make it show colors, or some alternative ways?
Just saw the linked list, but piping to less -R
or less -r
doesn't work. My OS is Ubuntu 12.04. less
is Version 444: 09 Jun 2011.
ls
(nottree
) for which some implementations need to be told to force color output when the output doesn't go to a terminal (in addition toless -R
being needed)tree -C | less -R
? The-C
option is tree's equivalent of less's--color=always
, I think (at least it works for me, on Ubuntu 12.04).tree
with and without-C
alone always output in colors, but why are they different when used withless
?less
removes the colors by default unless you give it the-R
option, which tells it to leave it in, and 2.tree
andls
and other programs usually turn coloring off when they detect their output is going to another program (likeless
) instead of directly to your terminal, unless you force the coloring on with-C
or--color=always
.