rsync compare directories?

To add to Nils's answer (for anyone coming across this via Google), by default rsync only compares the file sizes and modification times to tell if there are any differences. (If those are different it does more, but if they're the same, it stops there.)

If you want to compare actual file contents, even for files which have the same size and last modification time, add the flag -c to tell rsync to compare the files using a checksum.

rsync -avnc $SOURCE $TARGET

(The -u option tells rsync to ignore files which are newer in $TARGET than on $SOURCE, which you probably don't want if you're comparing contents.)


You will propably have to run something like rsync -avun --delete in both directions.

But what are you actually trying to accomplish?

Update:

rsync -avun --delete $TARGET $SOURCE |grep "^deleting " will give you a list of files that do not exist in the target-directory.

"grep delet" because each line prints : deleting ..file..

rsync -avun $SOURCE $TARGET will give you a list of "different" files (including new files).


Just for those less familiar with rsync:

rsync -rvnc --delete ${SOURCE}/ ${DEST}
  • -n : most important bit -- do not change anything ;
  • -rc : compare only the contents (otherwise use -ac) ;
  • -v : list the files )
  • --delete : look for a symmetrical, not a uni-directional difference.
  • Finally, / means "look inside the directory, and compare its contents to the destination".

It will print a usual rsync output,

  • with one <filename> on a line for every "new" file in ${SOURCE}
  • and one "deleting <filename>" line for each "new" file in ${DEST}.

  • It may also print a few warnings, like "skipping non-regular file <filename>" for symlinks.

PS. I know it's a terrible PS -- but it was indeed added in a rush. Nevertheless, I bet one may find this useful.


PPS. Alternatively, one could also do

find $SOURCE -type f -exec md5sum {} \; | tee source.md5
find $DEST   -type f -exec md5sum {} \; | tee dest.md5

If the filenames do not contain newlines, we can then sort both *.md5 files, and diff them. ( This will work only for files, though; that is, an empty directory on either side won't be detected. )