Excerpts from Simplify, Automate, Liberate! For Unix/Linux System Administrators
written by Gerald Yong
You have 2 different folders, and you want to compare the files in the folders to see if they are the same or different. The files have the same names in both folders.
Compute a fast hash or checksum for all the files would be a faster method.
You may be tempted to use diff to compare each file with its twin in the other folder to see if there are differences. However this will take much longer.
cksum will generate a unique number for specified files. Because cksum can generate the number quickly, it can be used as a quick way to see if 2 files have the same checksum, and hence determine if they are the same.
The cksum method is a fast method of comparing files, but do note that 2 files with the same contents but different last modified dates will still have the same checksum.
The script above uses cksum to generate checksums for all the files in each directory and stores them in a text file in each directory. It then uses diff to compare the text files, so that you can tell which files have different checksums.
Need more information? Looking for expert advice to implement a mid-range to
enterprise level backup/storage solution in your organisation?
Click on the image below to contact us!