I want to compare two directories, one is local and the other is on another machine.

How can I do that? Can I do it with diff?

link|improve this question
feedback

migrated from stackoverflow.com Oct 2 '11 at 10:07

This question came from our site for professional and enthusiast programmers.

3 Answers

I can think of two ways here..

  1. Mount your remote directory locally, and then use diff as you would do on a local machine.

  2. Use rsync:

rsync -avz --dry-run remote-user@remote-machine:remote-dir local-dir

This will show you the files that differ, but will not show you the actual diff. I think Unison supports diff also, but I have never used it and it does not seem to be under development any more.

link|improve this answer
the problem in rsync , it is work in just one direction . i use unison before , i search how i can do diff by using unison but the problem on unison it is can't do diff without sync folder – Eng Al-Rawabdeh Oct 2 '11 at 7:37
If you swap the order of directories in rsync, it will work in the other way. – Raze2dust Oct 2 '11 at 7:40
1  
I don't understand the comment about it working in only one direction. Being identical is commutative - if A is identical to B, then B is identical to A; if A is different from B, then B is different from A. If you're just looking for whether they're the same or not, there is no directionality. – Dave Sherohman Oct 2 '11 at 11:16
feedback

Note that using diff will require the entire contents of the remote directory to be transferred over the network, which could become prohibitively slow if there are large files or large numbers of files involved.

My recommendation would be to first determine which files differ between the two machines (by using rsync -n --delete (-n causes it to only tell you what it would do, but without actually doing it; --delete will tell you if any files exist in the destination, but not in the source, because it will want to delete them) or by comparing md5sums. If you're looking for how they're different (rather than just if they're different), I would then use diff only on those specific files to see what the differences are.

link|improve this answer
feedback

Yes, you can do it with diff! User space applications such as "diff" don't know (and don't need to know) if a directory is local or remote.

link|improve this answer
do you mean i can use ssh ?? – Eng Al-Rawabdeh Oct 2 '11 at 7:18
feedback

Your Answer

 
or
required, but never shown