Md5 checks

Everyone has heard of md5 checksums, that’s almost a given. But I must say that I did not use it except for very large files (iso’s and ilk…) because manually comparing the checksums was very cumbersome to do a lot of times.

Of course that if you have various files, you dump the checksums and files names into another file, and do something like this:

$ md5sum -c filename

where filename must contain one line for each file to check, in the following format:

<checksum value><TWO WHITESPACES><name of file to be checked>

Pay special attention to the fact that separation must be exactly two spaces, anything else will yield the cryptic error message:

no properly formatted MD5 checksum lines found

That said, if all have is one file and checksum to check, you can always do this:

$ echo ‘<checksum value><TWO SPACES><file to check>’ | md5sum -c

Note that the single quotes are necessary because otherwise echo will just put one space, and eliminate the extra space, thus making md5sum fail.

As an endnote, I found the two spaces thing by trying (and it not working) and with the help of Google. Unbelievably, in the md5sum manpage, while it says that you can put checksum and file name in a file as shown above, it gives no mention of the two spaces detail! I eventually found it to be the culprit of my successive failed attempts, and that’s the reason for writing this post: so you don’t have to waste as much time as I did.

EDIT 15/11/2008:

The exact same technique (two spaces included) works for SHA1 checksums, just replace (in Linux) ‘md5sum’ with ‘sha1sum’:

$ echo ‘<checksum value><TWO SPACES><file to check>’ | sha1sum -c

2 responses to “Md5 checks

  1. Wonderful! I must have looked at 15 sites before I found your information. Yours was the only one that explained how to use single quotes to protect the double whitespace from being collapsed when running md5sum –check on the command line. I’ve wanted this information for about 10 years!