Best way to compare (diff) a full directory structure?
Solution 1:
The tool your looking for is rdiff. It works like combining rsync and diff. It creates a patch file which you can compare, or distribute.
Solution 2:
Some people want to compare filesystems for different reasons, so I'll write here what I wanted and how I did it.
I wanted:
- To compare the same filesystem with itself, i.e., snapshot, make changes, snapshot, compare.
- A list of what files were added or removed, didn't care about inner file changes.
What I did:
First snapshot (before.sh
script):
find / -xdev | sort > fs-before.txt
Second snapshot (after.sh
script):
find / -xdev | sort > fs-after.txt
To compare them (diff.sh
script):
diff -daU 0 fs-before.txt fs-after.txt | grep -vE '^(@@|\+\+\+|---)'
The good part is that this uses pretty much default system binaries. Having it compare based on content could be done passing find
an -exec
parameter that echoed the file path and an MD5 after that.