compare two directory trees

The rsync utility first popped into my mind when I saw your question. Doing something like below could quickly show what files are in directory a but not in b:

$ rsync -rcnv a/* b/

-r will recurse into the directories
-c will compare based on file checksum
-n will run it as a "dry run" and make no changes, but just print out the files 
   that would be updated
-v will print the output to stdout verbosely

This is a good option because you can compare the contents of the files as well to make sure they match. rsync's delta algorithm is optimized for this type of use case. Then if you want to make b match the contents of a, you can just remove the -n option to perform the actual sync.

Some related questions:

  • https://stackoverflow.com/questions/19396718/compare-files-in-two-directory-on-remote-server-using-unix
  • https://unix.stackexchange.com/questions/57305/rsync-compare-directories

How about generating a recursive directory listing of each directory into separate files and then using diff on those two files?

Tags:

Stdin

Diff