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

md5 of a directory

Is there a way to generate an md5 sum for an entire directory (as opposed to a single file)? The md5 command only seems to accept files.

Thanks in advance.

Eric

MacBook Pro, Mac OS X (10.5.1)

Posted on Dec 28, 2007 8:29 AM

Reply
Question marked as Best reply

Posted on Dec 28, 2007 9:53 AM

Try "md5 directory/*" or
"find directory -type f -exec md5 {} \;"
9 replies

Dec 28, 2007 7:27 PM in response to Eric S

how about tar -cf test.tar someDir | md5 && rm test.tar???

the blue part creates a "tarball" (Tape ARchive) of the directory "SomeDir" and all its files and subdirectories recursively, and the gray part is an optional part to delete the tar file after you've run an md5 checksum on it.

If disk space is an issue while creating the temporary tarball, modify the command to read
tar -czf test.tgz someDir | md5 && rm test.tgz instead. This will create a compressed tarball to run the checksum against, and, as before, optionally delete the zipped tarball after the md5 has been run on it. This second way takes a bit longer to execute, though, but disk space savings during the lifetime of the tarball can be quite significant. You won't gain anything, disk space savings-wise, with ".mov" files or ".gpg" files but you sure will with text-type files, like .doc, or .txt or .rtf.

Dec 29, 2007 11:52 AM in response to Eric S

So, out of the three methods, it appears to me that Etresoft's "find" method gives you an MD5 checksum for each and every file nested in the directory of interest. Not sure if that's what you were looking for or not. My (j.v.) "nozip" tar method took 53 secs to spit out a single md5 checksum value for a 210,032,640-byte directory (my ~/Library) on a iBook G4/800, but it required a temporary allocation of free disk space the size of what I tarring/md5ing. Cole's method on that same directory (find ~/Library -type f -exec cat {} \; | md5), didn't require allocating any temporary disk space, and took 96 secs to spit out a single checksum value. I didn't time Etresoft's or my "tar&zip" methods. So there you have it -- three methods to do the same thing, each with their own advantages and disadvantages. Utilize as appropriate to your situation.

md5 of a directory

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