From LQWiki
(Redirected from MD5)
Jump to navigation Jump to search

md5sum is a program for verifying that contents of a file have been exactly reproduced without having access to the original file. It is often used for large files like ISO images that must be verified before they are used. A large number called the MD5 checksum (MD5sum) is calculated from the file's contents in a reproducible way that, with extremely high probability, will never produce the same MD5sum for different files. The user compares the MD5sum of the downloaded file to that obtained separately from the original source.

The algorithm is designed to make it difficult to tamper with the file while still producing the same MD5sum for the tampered file. If two instances of a file have the same MD5sum, the user is assured that the instances are identical. If one is the official version, so is the other.

To compute the MD5sum of a file (e.g., tmp.iso) and display it as a hex number, execute the command:

$ md5sum tmp.iso


You can use the -c option to md5sum to check the files against the md5sum file as below.

$ md5sum -c md5sum.txt 

To check the md5sum from a just burned dvd:

$ md5sum /dev/dvd

Trailing zero's and nuls at the end can change the MD5 hash. So to calculate the md5sum we need to:

  1. find the size of the ISO in bytes
  2. run dd with this exact size in bytes: dd if=/dev/dvd | head --bytes=<size> | md5sum

So for example:

$ dd if=/dev/dvd | head --bytes=3621957632 | md5sum

The Easiest way to test if an ISO has been correctly backed up is as follows:

I though the md5sum would be the best option and was proven wrong by myself. My conclusion was that the cmp command better answered my demands for testing CD or DVD disks after writing (It does not waste any time informing you whenever an error was found).

dd if=/dev/dvd | cmp tmp.iso


dd if=/dev/sr0 | cmp "Whatever my Long ISO Filename may be.ISO"

Testing should reveal that if the ISO Image is the same as the CD/DVD, you will have a result as follows:

9103360+0 records in

9103360+0 records out

4660920320 bytes (4.7 GB) copiedcmp: EOF on ISOFILENAME.ISO

{because and EOF on the ISO Image is specified, this output indicates that for all bytes read, the file is equal (Bytes in and out are the same for the full size of the ISO Image!) and that the only error that occured was that the End of the ISO file was reached before the end of the CD/DVD, which is usually irrelevant as we try to test accuracy of the burned image against a ISO Image. The reason for the EOF is that the written medium may exceed the ISO filesize (I assume this is padding/information for ISO, UDF and other extensions. I did not go into this as I am a Greenhorn myself). This example illiminates the use of md5sum command in which a file size in bytes must be provided to ensure that the bytes compared are the exact length of the ISO image which we are comparing to). In the CMP command case, size is not required as the comparison will end as soon as either the CD/DVD or ISO file have reached their end or an difference was encountered, whichever takes place 1st. If the ISO and CD/DVD differ, the result will tell you so by specifying - differ: char xxx, line xxx The advantage above md5sum is that the test will end immediately on determining an error which illiminates waiting until the very end should an error exist! md5sum does have its advantages but in this case the "cmp" command wins.

Provided by

Most (all?) Linux distributions incorporate this from the GNU Coreutils: and use its man page

Related commands

These are related to summarizing the contents of files.

External links