md5sum is a useful tool to verify if the file you downloaded from somewhere is correct

It compute and check MD5 message digest.

Binary mode

$md5sum -b mhvtl-2013-08-29.tgz
e4ed37674694937d7d776eb37fe18ca2 *mhvtl-2013-08-29.tgz

md5sum checksum verify

If you have a md5sum checksum, like this

cat mhvtl.md5
e4ed37674694937d7d776eb37fe18ca2 *mhvtl-2013-08-29.tgz

Then you can verify file's checksum

$md5sum -c mhvtl.md5
mhvtl-2013-08-29.tgz: OK

md5sum verify a list of files

If you have a list of file with their correct checksum in the file, the following command will report if there is file corrupted

$md5sum -c --quiet md5.lst
mtx-driveinfo.c: FAILED
md5sum: WARNING: 1 of 74 computed checksums did NOT match
$echo $?

String's checksum

$echo -n "I love dog, I love cat, I love both of them" |md5sum
1995bbc5dfc9117ccae88a25583b3f47  -

Note: '-n' option is needed, otherwise, an 'Ctrl+C' will be included in the string.

For example

$echo "I love dog, I love cat, I love both of them" |md5sum
ccb4ea2ab7fa3909c70205fa9be5a632 -
Same to
$md5sum -
I love dog, I love cat, I love both of them
ccb4ea2ab7fa3909c70205fa9be5a632 -

However, when using stand input to generate a string checksum, use Ctrl+D to end the string input

More for md5sum

       md5sum [OPTION]... [FILE]...

    Print or check MD5 (128-bit) checksums. With no FILE, or when FILE is -, read standard input.
     -b, --binary              read in binary mode
     -c, --check               read MD5 sums from the FILEs and check them
     -t, --text                read in text mode (default)             
Note: There is no difference between binary and text mode option on GNU system.
The following three options are useful only when verifying checksums:
       --quiet                   don’t print OK for each successfully verified file
       --status                  don’t output anything, status code shows success
       -w, --warn              warn about improperly formatted checksum lines
       --help                    display this help and exit
       --version                output version information and exit
The sums are computed as described in RFC 1321.  When checking, the input should be a former 
output of this program.  The default mode is to print a line with checksum, a character
indicating type (‘*’ for binary, ‘ ’ for text), and name for each FILE.

There is no different between -b and -t on GNU system.

Comments powered by CComment