This tutorial explains Linux “md5sum” command, options and its usage with examples.
md5sum [OPTION]… [FILE]…
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; 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
md5sum command is not usable for the directories.
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.
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):
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):
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.
- Apply for Programming Internship
- Buy Information Technology Books
- Practice Programming MCQs
- Apply for Linux Internship
- Buy Linux Books