Recursively generate MD5 checksums
Posted 10-26-2011 at 09:53 AM by Garda
I wanted to generate MD5 checksums of a whole bunch of files in a directory. It turns out that this is not as straightforward as it should be. IMO it should be completed with: md5sum -br *
Unfortunately it was not as straightforward. I found this blog entry after searching for a while and adapted this to what I needed. To generate checksums, I used the following:
(Note: for the above to work, "cd" to the top level directiory, or use "find /home/username/folder/" instead of "find .")
Some explanation. The "find" command is used to list filenames based on a particular search. "-type f" lists only files (ie. "-type d" lists only directories). "-print0" is an option to use if the filename contains newline characters, it instead finishes entries with a NULL character. Correspondingly, the "-0" switch needs to be used with "xargs".
"xargs" is used to build commands using piped input. So the above basically repeats everything after the "-0" switch over and over with the input from "find" appended each time. If you want to use a different command, just replace "md5sum -b" with any other command.
Also, if sums are stored to a text file, they can be verified using:
Unfortunately it was not as straightforward. I found this blog entry after searching for a while and adapted this to what I needed. To generate checksums, I used the following:
Code:
find . -type f -print0 | xargs -0 md5sum -b
Some explanation. The "find" command is used to list filenames based on a particular search. "-type f" lists only files (ie. "-type d" lists only directories). "-print0" is an option to use if the filename contains newline characters, it instead finishes entries with a NULL character. Correspondingly, the "-0" switch needs to be used with "xargs".
"xargs" is used to build commands using piped input. So the above basically repeats everything after the "-0" switch over and over with the input from "find" appended each time. If you want to use a different command, just replace "md5sum -b" with any other command.
Also, if sums are stored to a text file, they can be verified using:
Code:
md5sum -c filename.txt
Total Comments 0