Finding Differences

Finding Differences

If you’re like me, documents take up no small part of your life. Whether they’re text or formatted by some other word processing program, I’ve always got a pile of revisions awaiting review and collation.

diff is the program for you if you’re looking to compare those document revisions. diff works by comparing two text documents and outputting the lines that differ from one to the other. The convention for using diff is:

    diff [options] [diroptions] file1 file2

diff will also compare files within directories. For example, let’s say you’ve got a “new” directory and an “old” directory containing similar filenames. Given directory names as arguments, diff will report back all differing lines between similar filenames in both directories.

Here’s a set of options to utilize when using diff:

Option Action
a treat all files as text files
b ignore repeating and end-of-line blanks
B ignore blank lines
c context diff – print 3 lines surrounding each changed line
d ignore sets of numerous changes and output a smaller set
H display only scattered small changes, large sections with many changes may not appear
i ignore case changes
q output only whether files differ
r compare subdirectories recursively
w ignore all whitespace in files

Looking for differences? diff will root them out without a problem.