Linux‎ > ‎

md5sum useful examples

Thank you for visiting this page, this page has been update in another link md5sum useful examples
md5sum is a useful tool to verify if the file you downloaded from somewhere is correct, it's simple but have some different use cases.
As it's said in man page, it compute and check MD5 message digest.

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

DESCRIPTION
       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, so in following examples we use default -t option.

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

Example #2 Report md5sum check result
$md5sum mhvtl-2013-08-29.tgz >mhvtl.md5
$md5sum -c mhvtl.md5
mhvtl-2013-08-29.tgz: OK

Example #3 Report only result
$md5sum -c --status mhvtl.md5
$echo $?
0

Example #4 I generated a list of file into md5.list, changed one of them
$md5sum -c --quiet md5.lst
mtx-driveinfo.c: FAILED
md5sum: WARNING: 1 of 74 computed checksums did NOT match
$echo $?
1

Example #5, when using - as option, md5sum accepts STDIN input, note the third one is a bit different.
$echo "I love dog, I love cat, I love both of them" |md5sum
ccb4ea2ab7fa3909c70205fa9be5a632  -

$md5sum -

I love dog, I love cat, I love both of them
ccb4ea2ab7fa3909c70205fa9be5a632  -

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


Note: use Ctrl+D to signal end of string, not Ctrl+C, which is a interrupt signal.





Comments