

The -n option ( -dry-run) makes sure that no file is actually transferred to dir2. The above will output a line for each file anywhere under dir1 that does not have a corresponding file under dir2. diff -q may quiet it down a bit in that case.įor comparing deeper hierarchies, you may want to use rsync: $ rsync -r -ignore-existing -i -n dir1/ dir2 If the file contents of files with identical names differ, then this would obviously output quite a lot of additional data that may not be of interest. If the files in the two directories not only have the same names, but also the same contents, you may use diff (note: BSD diff used here, GNU diff may possibly say something else): $ diff dir1 dir2 The loop, written out more verbosely (and using basename rather than a parameter substitution to delete the directory name from the pathname of the files in the first directory): for f1 in dir1/* do

If that file does not exist, its name is printed.

This loops through all the names in the first directory, and for each creates the corresponding name of a file expected to exist in the second directory.
