5 Practical “md5sum” Command Usage Examples in Linux

«
»

This tutorial explains Linux “md5sum” command, options and its usage with examples.

“md5sum” command is used to compute and check MD5 message digest. This post describes “md5sum” command used in Linux along with usage examples and/or output.

Usage:
md5sum [OPTION]… [FILE]…

advertisement

The MD5 message-digest algorithm is a widely used cryptographic hash function that produces a 128-bit (16-byte) hash value.Two non identical files will never have the same md5sum value.However, it has since been shown that MD5 is not collision resistant;[3] as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property.

Here’s the listing of example usage of “md5sum” command:

1. To calculate md5sum(md5sum file_path):

sanfoundry-> md5sum out.txt 
fa328c3f84352dc7ff5e32bba2ac833c  out.txt

Note
md5sum command is not usable for the directories.

advertisement
advertisement

2. To compute and verify checksum of files(md5sum -c file_path):

sanfoundry-> md5sum *.txt 
d41d8cd98f00b204e9800998ecf8427e  1.txt
743268534af6fb128bf4dd7f4914b1c8  2.txt
d41d8cd98f00b204e9800998ecf8427e  link.txt
fa328c3f84352dc7ff5e32bba2ac833c  out.txt
sanfoundry-> md5sum *.txt > x.md5
sanfoundry-> md5sum -c x.md5 
1.txt: OK
2.txt: OK
link.txt: OK
out.txt: OK

“-c” option checks the status of the files and if there is any change it gives error.

advertisement
sanfoundry-> vi 1.txt 
sanfoundry-> md5sum -c x.md5 
1.txt: FAILED
2.txt: OK
link.txt: OK
out.txt: OK
md5sum: WARNING: 2 computed checksums did NOT match

If link.txt is the link file of 1.txt then it also get changed and md5sum also FAILED to cross verify it.

sanfoundry-> vi 1.txt 
sanfoundry-> md5sum -c x.md5 
1.txt: FAILED
2.txt: OK
link.txt: FAILED
out.txt: OK
md5sum: WARNING: 2 computed checksums did NOT match

3. To read in binary mode(md5sum -b file_path):

advertisement
sanfoundry-> md5sum 1.txt 
764efa883dda1e11db47671c4a3bbd9e  1.txt
sanfoundry-> md5sum -b 1.txt 
764efa883dda1e11db47671c4a3bbd9e *1.txt
sanfoundry-> md5sum --binary 1.txt 
764efa883dda1e11db47671c4a3bbd9e *1.txt

“-b” option is equivalent to “–binary” option.
Treat all input files as binary. This normally does not make any difference on UN*X systems but some systems have a different internal and external representation of texts (especially the end-of-line characters).

4. To read in text mode(md5sum -t file_path):
Treat all input files as text files. This is the reverse option to –binary.

sanfoundry-> md5sum -t 1.txt 
764efa883dda1e11db47671c4a3bbd9e  1.txt

5. To print version information on standard output then exit(md5sum -v):

advertisement
sanfoundry-> md5sum --version
md5sum (GNU coreutils) 8.13
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
 
Written by Ulrich Drepper, Scott Miller, and David Madore.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.