Home > diff, howto > Compare two directories using diff

Compare two directories using diff

April 23rd, 2008 grady

As mentioned in other hints, diff can not only compare two files, it can, by using the -r option, walk entire directory trees, recursively checking differences between subdirectories and files that occur at comparable points in each tree. The trick is to use the -q option to suppress line-by-line comparisons in files that differ:

diff -rq dirA dirB

This command will provide a nice list of files that occur in dirA but not in dirB, files that occur in dirB, but not in dirA, and files that differ between dirA and dirB. Pipe the output through grep to remove mention of uninteresting files, and sort to tidy it up, e.g.:

diff -qr dirA dirB | grep -v -e ‘DS_Store’ -e ‘Thumbs’ | sort > diffs.txt

Categories: diff, howto Tags:
Comments are closed.