Md5sum

From Wikipedia, the free encyclopedia

The correct title of this article is md5sum. The initial letter is shown capitalized due to technical restrictions.

md5sum is a computer program which calculates and verifies MD5 hashes, as described in RFC 1321. The MD5 hash (or checksum) functions as a compact digital fingerprint of a file. It is extremely unlikely that any two non-identical files will have the same MD5 hash (although it is faintly possible).

Because almost any change to a file will cause its MD5 hash to also change, the MD5 hash is commonly used to verify the integrity of files (i.e., to verify that a file has not changed as a result of file transfer, disk error, human meddling, etc.). The md5sum program is installed by default in most Unix, Linux, and Unix-like operating systems or compatibility layers. Versions for Microsoft Windows do exist (see external links). BSD variants (including Mac OS X) have a similar utility called md5.

[edit] Usage

To calculate the MD5 hash of a file under many Unix and Linux operating systems, simply give the filename as an argument to md5sum (the following commands are not applicable to Windows XP, Apple II or Commodore 64).

$ md5sum somefile
76c6dafd6569222312357fdfdbace3e5  somefile

You can then compare the MD5 hash of your file, to the known good hash of the file you are checking. If the two values match, you are overwhelmingly likely to have an exact copy of the original file.

The output of md5sum can be saved into a text file and used to verify the integrity of a file. If the output above is stored in the file somefile.md5, the following command will compare the MD5 hash of somefile with the hash stored in somefile.md5.

$ md5sum -c somefile.md5
somefile: OK

The md5sum command can also be used in an interactive mode to calculate the MD5 hash of any arbitrary string of characters. After typing the md5sum command without any arguments, type the string of characters in the terminal. End the string with an End-of-file character. The MD5 hash will be displayed on the terminal next to the input string. For example:

$ md5sum
somestring CTRL+D CTRL+D 

will result in the following output.

$ md5sum
somestring1f129c42de5e4f043cbd88ff6360486f  -

Microsoft offers an unsupported tool "Microsoft File Checksum Integrity Verifier" for Windows platform. The default mode of generating the checksum on Linux systems is in "text-mode", however, in MS-Windows, it is in binary. Hence, MD5 files created in MS-Windows systems will have an "*" before the filename.

C:\> md5sum test.txt
1bd3cb2ef387818ebe0fc318c232e27d *test.txt

You will need to remove them before they are accepted by Linux systems. A fast way of doing it would be to use the following:

$ cat md5sum | sed -e 's/*//' >new_md5sum

Note that after removing the "*" these files can no longer be checked under MS-Windows, as the default check is now changed to binary and the files indicate that they are in text-mode. (See Linux man-page for command-line options)


On recent versions of Apple's Macintosh OS X, the md5sum program is not included, but it can be installed in various ways. Through DarwinPorts with the command "port install coreutils". The md5sum program will then be available as "gmd5sum" rather than "md5sum", but the command line options are the same as described above. If Fink is available, the command "fink install coreutils" will work (and will not prepend the letter g to the commands). If Xcode is installed, md5sum can be compiled and installed directly from the gnu source by downloading coreutils and doing ./configure; make; sudo make install.

[edit] See also

[edit] External links

In other languages