Wednesday 11 February 2009

Verifying that bulk file copy

If you copy a bunch of files/folders from one disk to another and want to verify they have all copied correctly without corrupting, you can use cygwin and md5sum to verify them.

In cygwin run the following commands:

cd /cygdrive/[drive letter]/
[path]
e.g. cd /cygdrive/c/test. This is the source path to generate the MD5 hashes from.

find . -type f 2>/dev/null -exec md5sum {} \; >/cygdrive/c/temp/test.md5
This generates the md5 file which is a plain text file containing the MD5 hashes. Depending on the size of files to verify this might take a while. There may also be issues with files over 2GB in size (I haven’t tested this).

cd /cygdrive/[drive letter]/[path]
e.g. cd /cygdrive/d/destination. This is the destination where you copied the files to.

md5sum –c /cygdrive/c/temp/test.md5 | grep –i failed >/cygdrive/c/temp/test-result.log
This checks the copied files against the md5 hashes and filters the output through grep to only include failed files. c:\temp\test-result.log will contain the results of the verify.
The result is either “ok” or “failed” but you’re probably only interested in the failed files.