Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
Check Tim Long's answer and Beyond Compare. –  Stein Åsmul Jul 22 at 16:44

9 Answers 9

up vote 15 down vote accepted

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.

share|improve this answer
    
Thanks! I'll look into it. –  Adam Matan Jul 12 '09 at 11:26

Try Beyond Compare 3 (Scooter Software) which has versions for Windows and Linux. Once you've used it, you will probably not want to use any other file comparison tool.

share|improve this answer
1  
+1 for an exceptional tool –  Steven Sudit Jul 12 '09 at 22:01
1  
+1 for a good recommendation. –  djangofan Oct 29 '09 at 20:54
    
Winmerge works just as good. –  djangofan Nov 6 '09 at 20:46
    
This is the tool written by guys who eat their own dog food. It's slick, tasty, feature complete for the purpose and keeps getting better - not worse - unlike many tools that turn into bloatware. Wikipedia page and Comparison to other, similar apps and finally the Beyond Compare Web Page. No affiliations obviously. –  Stein Åsmul Jul 22 at 16:42

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...

share|improve this answer

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.

share|improve this answer
    
Thanks, but it does not solve my problem (I'm looking for the diff to actually tell the differences). –  Adam Matan Jul 12 '09 at 11:09

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.

share|improve this answer

I would use Meld for that.

share|improve this answer
    
Meld works really well for this if you want a GUI solution. –  Drew Noakes Mar 4 '13 at 11:58

Besides the tools already mentioned on windows you could use Total Commander or WinSCP, both have very comfortable functions to compare (and sync) directories.

share|improve this answer

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.

share|improve this answer

diff -r actually works quite well. If you just want to know if the files differ, not the actual contents of the differences, then do diff -qr

share|improve this answer
1  
-r means recursive, it does not connect to a remote host! –  Michael Hampton Jul 22 at 16:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.