How to color code ‘diff’ output on CLI?

TL;DR :  vim -d <file1> <file2>

Comparing changes in files from time to time is very much the part and parcel of a Linux Admin.’s life. The diff command is pretty well known and handy, but what it lacks is the color coding option to make the comparisons more readable!

I found a similar question on stackoverflow  -> How to colorize diff on the command line? , but I needed something which also highlights the exact difference eg. the ‘.’ or various versions of <‘ ` “> which creep in the scripts and make devops difficult!

colordiff <file1> <file2> seems to provide partial solution. It color codes and improves readability, but does no assistance in highlighting in exact modifications.


vim comes to rescue herevimdiff is the command I was looking for. It also, allows you to compare up to four files at the same instance.

vim -d is an alias for vimdiff and can be used as

vim -d /path/to/file1 /path/to/file2


You get the line which has changes, as well as the modified part highlighted.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s