After copying a folder, restoring a backup or syncing two machines, I want to know if both sides really match. diff can compare whole trees.
diff -qr /srv/site /mnt/backup/site
-r walks through all subfolders and -q keeps it short: instead of showing what changed inside each file, it only says which ones differ. The output has lines like these:
Files old/f.txt and new/f.txt differ
Only in old: gone.txt
Only in new/sub: added.txt
No output and exit status 0 means the trees are identical, which makes it easy to use in a script.
To skip noise like logs or caches, add -x with a pattern. It matches file and folder names, and you can give it more than once:
diff -qr -x '*.log' -x cache /srv/site /mnt/backup/site
diff reads every file that exists on both sides completely, so on a big media folder this takes as long as reading all the data twice. That’s also why it’s trustworthy: it compares content, not sizes or dates. If you only want a quick check of names and sizes, rsync -rn --itemize-changes is faster. And diff doesn’t compare permissions or owners at all, so a restore with wrong ownership still looks identical here.
Further reading: diff(1) manual page, GNU diffutils manual