What's the best way to compare directory structures?
I have a backup utility which uses rsync. I want to tell the exact differences (in terms of file sizes and last-changed dates) between the source and the backup.
Something like:
Local file Remote file Compare
/home/udi/1.txt (date)(size) /home/udi/1.txt (date)(size) EQUAL
/home/udi/2.txt (date)(size) /home/udi/2.txt (date)(size) DIFFERENT
Of course, the tool can be ready-made or an idea for a python script.
Many thanks!
Udi
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.
I wanted:
What I did:
First snapshot (
before.sh
script):Second snapshot (
after.sh
script):To compare them (
diff.sh
script):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.if you don't feel like installing another tool...
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.
diff -r
actually works quite well. If you just want to know if the files differ, not the actual contents of the differences, then dodiff -qr
From rsync man page:
May be this will help.
I would use Meld for that.
I didn't really want to install anything new, so my solution is a bit crude, but quick and effective.
I wanted to compare all files have been copied and their file mode, ownership and SELinux security context remain unchnaged.
So I ran:
and then compare like this:
If the contents of both files remain collapsed then they are identical. If not, the diff is shown.
Update parameters of
ls
to reflect the attributes you need to check. YMMVBesides the tools already mentioned on windows you could use Total Commander or WinSCP, both have very comfortable functions to compare (and sync) directories.