2 Answers
2

Most likely your ls is aliased to ls --color=auto, which tells ls to only use colors when its output is a tty. If you do ls --color (which is morally equivalent to ls --color=always), that will force it to turn on colors.

You could also change your alias to do that, but I wouldn't really call that a good idea. Better to make a different alias with --color.

Why would you not call it a good idea to alias ls to ls --color or ls --color=always, for that matter?
–
j08lueApr 8 at 13:38

@j08lue if you pipe through a command that doesn't handle color, you get some junk characters that may mess up the command. For example, I did ls --color=always | less and got: ESC[01;32mexecute_once.shESC[0m (I know this is old and you probably don't care, but for future visitors, this may be useful)
–
Ryan AmosJun 30 at 16:51

@Scott Biggs: in OSX there is no --color; try ls -G
–
Lu-ChiJan 3 at 6:34

@Lu-Chi, Even with -G, the colors are missing
–
Iulian OnofreiFeb 6 at 10:26

In OS X you need to set the environment variable CLICOLOR_FORCE (to anything) when the output of ls isn't directed to a terminal. This works for me: CLICOLOR_FORCE= ls -G | less -R
–
jooonFeb 11 at 15:15