Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to use md5 Checksums to verify thousands of copied files

Hello,


So I need to be able to verify the succesful copy of thousands of files using md5 checksums.


is there a program for this or a string of code for terminal?


Please help.


Cheers.

MacBook Pro, OS X Mountain Lion (10.8.4)

Posted on Jul 10, 2013 11:06 PM

Reply
10 replies

Jul 11, 2013 9:17 PM in response to JulianLawrence

I cover how to do that in the link above, but to quickly do this, run the following command on both folder paths:


find -s ~/Downloads -type f -exec md5 -q {} \; | md5


This will generate a list of md5 checksums for each file in the directory (in this case, the Downloads directory in your home folder, but you can change this to whatever you would like), and then create a summary checksum of the collective checksums.


In my case, the above command yields the following checksum:


42cf9632cf763cad84c633f0cc7c93bb


Doing this on my Documents folder yields the following checksum:


782845544f0ecf8a7ae5fa66197d6abd


You can then compare these to see if they are different. In this case they are, indicating the folders do not have the same contents.


Keep in mind this may take a while to run, as checksums will have to be computed for each file in the directory. While this is a raw command, you can save it in a script and then simply run the script with an input argument to make it easier. For example, the following script should work:


#!/bin/bash

find -s $1 -type f -exec md5 -q {} \; | md5


Saving this in a text file, naming it something like "dirsum" and then making it executable in a path location such sa /bin (or a custom added path) will make it easily accessible, so you can run the same command by simply typing the following in the Terminal (in this case to calculate a checksum of the Downloads folder):


dirsum ~/Downloads

Jul 11, 2013 10:14 PM in response to JulianLawrence

What are the two commands specifically that you are running? Some examples of how it should be run are the following:


For the Downloads folder in your home directory:


find -s ~/Downloads -type f -exec md5 -q {} \; | md5


For the Movies folder in your home directory:


find -s ~/Movies -type f -exec md5 -q {} \; | md5


For the Applications > Utilities folder:


find -s /Applications/Utilities -type f -exec md5 -q {} \; | md5


For the entire file system:


find -s / -type f -exec md5 -q {} \; | md5


In some cases you may need to run the command with "sudo" in front of it (followed by supplying your password, when prompted), to ensure it has full access to the files in the directory. This is especially true for folders copied by other user accounts, or those in some system folders, and will look like the following:


sudo find -s /Users/username/Documents -type f -exec md5 -q {} \; | md5

Jul 16, 2013 12:08 AM in response to JulianLawrence

Thanks once again for all your help,




I ended up creating a script that creates a checksum text file then I use the "comm" command to compare the two.



find -s "$@" -type f -exec md5 '{}' \; > "$@"/checksums.md5
cat "$@"/checksums.md5 > "$@"/checksums.txt





This generates a .txt file with a list of all the checksums generated by all the files in that directory, then I just compared them 🙂








How to use md5 Checksums to verify thousands of copied files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.