I've been using git diff, which produces colored output. However, I now find I need to use ordinary diff for something, and it's producing a lot of output that is hard to read because of the lack of colors. How do I make diff produce a readable, colored output? Ideally while piping it to less, for easy review of large files.
How to pipe colored diff output to less
colorsdiff()less
Best Answer
diff
cannot output colors, you need another program, such ascolordiff
for that. Colors in the terminal are printed via ANSI escape codes which less does not interpret by default. To getless
to correctly show colors, you need the-r
, or even better,-R
switch:From
man less
:Alternatively, you can use
more
which will display colors correctly by default.If you cannot install external programs, you should be able to get the same output using a more manual approach: