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.

colordiff

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

vim

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:

WordPress.com Logo

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s