Show escaped bash color codes in less #linux

June 11, 2018|
1 min read
  • command-line

Originally posted by me on Hashrocket TIL

My ls command colors directories and files according to their type and permissions:

ls with color

But when the window is too small to fit the content I pipe the result into less:

less broken

Which cannot correctly parse the escape code from ls and turn them into color. To fix that add -r to the less command:

solution

Notes:

My l alias is gls -F -G --color --group-directories-first -lah (gls is GNU ls)

You can alias less=less -r if you want this to be the default behavior for less.


© 2023, Dorian Karter