Skip to content
Fragmented Development

Color ls output in less

Something that has always bothered me is that my beautiful, colorful ls command output is converted to stark, monochrome text whenever I pipe it to less. Syntax highlighting is extremely helpful when it comes to differentiating directories from normal, extension-less files.

Through a couple sessions of research and stumbling upon a helpful switch in the ls man page, I've come up with this embarrassingly simple command:

ls --color=always | less -R

That's it. Using --color=always on ls forces it to send color escape sequences to less, and -R forces less to pass them on to your terminal, which renders them in a glorious rainbow of your choosing.

I am immediately adding this to my RC file as default arguments, although you may want to be careful. This could potentially mess up scripts dependent on parsing raw ls output.

Tags: linux


Add Your Comment