Thursday, February 21, 2013

Comparing directories

Here's how to compare the filenames (not the content of the files!) of two directories:
rsync -nav --delete dir1/ dir2/

NOTE! Don't forget the -n option, otherwise the files from dir1 will be copied to dir2!

The slash ('/') after the directory names is necessary, otherwise it will also check for dir1 resp. dir2 in the path name.

This command will output all files from dir1 which don't exist in dir2. Files only existing in dir2 will be prefixed with 'deleting', because of the delete option.

To check also for differences in the file's contents, use diff:
diff -qr dir1 dir2

The -q option omits the output of the actual difference in the files and provides a better readable output. -r scans directories recursively.

No comments:

Post a Comment