Using ls or many other commands, we can get colorful results like this:

But if those results are too long and after we pipe those results to less, the color is disappeared.
This is the result of ls -l | less:

ls | less colorful?You need to pass --color option to the ls command on Linux. If you are using OS X or BSD based system pass -G option to the ls command. The syntax is as follows to turn on or off colors.
Color output for ls is typically enabled through an alias in most distros nowadays. You can always disable an alias temporarily by prefixing it with a backslash. Doing the above will short circuit the alias just for this one invocation. You can use it any time you want to disable any alias.
From the man page for ls:
Using the
--coloroption 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).
Note that always is the default.
From the man page for less:
-r or --raw-control-charsCauses "raw" control characters to be displayed.
So overall, you need this:
ls -l --color | less -r
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With