How can I calculate an md5 checksum of a directory?

victorz picture victorz · Nov 1, 2009 · Viewed 144.5k times · Source

I need to calculate a summary md5 checksum for all files of a particular type (*.py for example) placed under a directory and all sub-directories.

What is the best way to do that?

Edit: The proposed solutions are very nice, but this is not exactly what I need. I'm looking for a solution to get a single summary checksum which will uniquely identify the directory as a whole - including content of all its sub-directories.

Answer

ire_and_curses picture ire_and_curses · Nov 1, 2009

Create a tar archive file on the fly and pipe that to md5sum:

tar c dir | md5sum

This produces a single md5sum that should be unique to your file and sub-directory setup. No files are created on disk.