Given two directory trees, how can I find out which files differ by content?

Mansoor Siddiqui picture Mansoor Siddiqui · Feb 14, 2011 · Viewed 536k times · Source

If I want find the differences between two directory trees, I usually just execute:

diff -r dir1/ dir2/

This outputs exactly what the differences are between corresponding files. I'm interested in just getting a list of corresponding files whose content differs. I assumed that this would simply be a matter of passing a command line option to diff, but I couldn't find anything on the man page.

Any suggestions?

Answer

Mark Loeser picture Mark Loeser · Feb 14, 2011

You said Linux, so you luck out (at least it should be available, not sure when it was added):

diff --brief --recursive dir1/ dir2/ # GNU long options
diff -qr dir1/ dir2/ # common short options

Should do what you need.

If you also want to see differences for files that may not exist in either directory:

diff --brief --recursive --new-file dir1/ dir2/ # GNU long options
diff -qrN dir1/ dir2/ # common short options