Well the answer is in the man pages, from “man ls”:
By default, color is not used to distinguish types of files. That is equivalent to using --color=none. Using the --color option without the optional WHEN argument is equivalent to using --color=always. With --color=auto, color codes are output only if standard output is connected to a terminal (tty). The environment variable LS_COLORS can influence the colors, and can be set easily by the dircolors command.
My emphasis above shows why ls won’t pipe through less properly and keep the colors. Now I had an alias in my
lh='ls --color=auto -lasth | less -R'
This at first glance looks like it pipes ls through less and keeps the colour codes (see
man less for what the -R switch does). It does, only ls doesn’t send the colour codes because it doesn’t think it’s being output to a TTY (see quoted man above). So all you need to do is ensure that
--color=always is set (
--color=yes appears to work too but may not be POSIX compliant). HTH, happy bash-ing!