Piping ls through less with colors on Mac OS X

June 13, 2012

The following command will do the trick:

CLICOLOR_FORCE=1 ls -G|less -R

Or just add this to your .bash_profile file to have ls always display in color and less always able to consume color codes:

alias ls='CLICOLOR_FORCE=1 ls -G'
alias less='less -R'

This has been tested on 10.6.8 and should be valid for subsequent versions as well. Just a tad annoying since ls on Mac OS X behaves a bit differently than the standard linux one (i.e. no --color option).

Piping ls through less with colors on Mac OS X - June 13, 2012 - Michael Katsevman