9. How do I compare the content of two directories?
The build in tools diff, comm, find and sort in macOS and Linux can be used to compare two directories to see if anything is changed.
Let us assume the files are in the directories called directory1 and directory2.
Finding difference in content
For large datasets this will take some time because the content of all files will be read and compared.
diff -r directory1 directory2
Finding missing or added files
This will be faster because only the list of files and directories in the two directories are compared. The content is not compared. All file names that do not exist in both are printed.
comm -3 <(cd directory1 ; find | sort) <(cd directory2 ; find | sort)
This displays files and directories that are unique for directory1.
comm -23 <(cd directory1 ; find | sort) <(cd directory2 ; find | sort)
This displays files and directories that are unique for directory2.
comm -13 <(cd directory1 ; find | sort) <(cd directory2 ; find | sort)