Best way to compare (diff) a full directory structure?
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.
Some people want to compare filesystems for different reasons, so I'll write here what I wanted and how I did it.
- 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 (
find / -xdev | sort > fs-before.txt
Second snapshot (
find / -xdev | sort > fs-after.txt
To compare them (
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
-exec parameter that echoed the file path and an MD5 after that.
if you don't feel like installing another tool...
for host in host1 host2 do ssh $host ' cd /dir && find . | while read line do ls -l "$line" done ' | sort > /tmp/temp.$host.$$ done diff /tmp/temp.*.$$ | less echo "don't forget to clean up the temp files!"
And yes, it could be done with find and exec or find and xargs just as easily as find in a for loop. And, also, you can pretty up the output of diff so it says things like "this file is on host1 but not host2" or some such but at that point you may as well just install the tools everyone else is talking about...
I've used dirdiff in the past to compare directory structures. It only works on local dirs so you will have to
sshfs-mount your other directories.
The good thing is that you can see visually if the files are equal or not and which one is newer or older. And it supports up to 5 directories. You can also see differencies and copy files from one to the other.
From rsync man page:
-n, --dry-run This makes rsync perform a trial run that doesn’t make any changes (and produces mostly the same output as a real run). It is most commonly used in combination with the -v, --verbose and/or -i, --itemize-changes options to see what an rsync command is going to do before one actually runs it.
May be this will help.