When I read a file in Linux with the command less
or more
, how can I get the content in colors?
linux – How to Get Colored Content When Reading a File with Less or More
colorslesslinux
colorslesslinux
When I read a file in Linux with the command less
or more
, how can I get the content in colors?
Best Answer
(update on 2020)
The faster way would be using
less -R
ref. https://superuser.com/a/117842/34893You can utilize the power of pygmentize with less - automatically! (No need to pipe by hand.)
Install
pygments
with your package manager or pip (possibly calledpython-pygments
) or get it here http://pygments.org/download/.Write a file
~/.lessfilter
In your
.bashrc
addAlso, you need to make
~/.lessfilter
executable by runningTested on Debian.
You get the idea. This can of course be improved further, accepting more extensions or parsing the shebang for other interpreters than bash. See some of the other answers for that.
The idea came from an old blog post from the makers of Pygments, but the original post doesn't exist anymore.