{"id":3172,"date":"2018-03-19T18:23:27","date_gmt":"2018-03-19T15:23:27","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-md5sum\/"},"modified":"2018-03-19T18:23:27","modified_gmt":"2018-03-19T15:23:27","slug":"linux-md5sum-command-tutorial-for-beginners-5-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-md5sum-command-tutorial-for-beginners-5-examples\/","title":{"rendered":"Linux md5sum Command Tutorial for Beginners (5 Examples)"},"content":{"rendered":"<p>While we have already discussed <a href=\"https:\/\/www.howtoforge.com\/linux-cksum-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">the cksum command line utility<\/a>, there&#8217;s another tool that you can use in scenarios where, say, you need to verify the integrity of files during transfers. The tool we&#8217;re talking about here is <strong>md5sum<\/strong>. In this tutorial, we will discuss the basics of this command using some easy to understand examples.<\/p>\n<p><em>Bue before we do that, it&#8217;s worth mentioning that all examples in this article have been tested on Ubuntu 16.04 LTS.<\/em><\/p>\n<h2 id=\"linux-mdsum-command\">Linux md5sum command<\/h2>\n<p>The md5sum command basically computes and checks MD5 (128-bit) message digest for files. Here&#8217;s the syntax of the command:<\/p>\n<p class=\"command\">md5sum [OPTION]&#8230; [FILE]&#8230;<\/p>\n<p>The following Q&amp;A-styled examples should give you a better idea of how md5sum works.<\/p>\n<h2 id=\"q-how-mdsum-command-works\">Q1. How md5sum command works?<\/h2>\n<p>Basic usage is pretty simple &#8211; if you want to compute MD5 checksum for a file, all you have to do is to pass the name of the file as input to the command. For example:<\/p>\n<p class=\"command\">md5sum testfile.txt<\/p>\n<p><a class=\"fancybox\" id=\"img-md5sum-basic-usage\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/md5sum-basic-usage.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-md5sum-command-tutorial-for-beginners-5-examples.png\" alt=\"How md5sum command works\" width=\"418\" height=\"35\" title=\"\"><\/a><\/p>\n<p>You can also redirect the output to a text file so that you can later check the digest against any change\/corruption in the file.<\/p>\n<p class=\"command\">md5sum test.txt &gt; digest.md5<\/p>\n<p>Use the <strong>-c<\/strong> command line option to check the digest.<\/p>\n<p class=\"command\">md5sum -c digest.md5<\/p>\n<p><a class=\"fancybox\" id=\"img-md5sum-c-option\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/md5sum-c-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-md5sum-command-tutorial-for-beginners-5-examples-1.png\" alt=\"md5sum -c option\" width=\"416\" height=\"37\" title=\"\"><\/a><\/p>\n<p>And if there&#8217;s any change or corruption, here&#8217;s the kind of output md5sum produces:<\/p>\n<p><a class=\"fancybox\" id=\"img-md5sum-c-option2\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/md5sum-c-option2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-md5sum-command-tutorial-for-beginners-5-examples-2.png\" alt=\"compare files with md5sum command\" width=\"454\" height=\"55\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-change-way-files-are-read-checksum-is-created\">Q2. How to change way files are read checksum is created?<\/h2>\n<p>By default, the md5sum command\u00a0reads input in text mode. However, if you want, you can make the tool read input in binary mode as well. This you can do using the <strong>-b<\/strong> command line option.<\/p>\n<p class=\"command\">md5sum -b [filename]\n<p>Plus, you can also force md5sum to create a BSD-style checksum using the <strong>&#8211;tag<\/strong> command line option.<\/p>\n<h2 id=\"q-how-to-make-mdsum-ignore-missing-files\">Q3. How to make md5sum ignore missing files?<\/h2>\n<p>While verifying checksums, if you want md5sum to neither fail nor report status for missing files, then you can use the <strong>&#8211;ignore-missing<\/strong> option. Following screenshot shows this option in action:<\/p>\n<p><a class=\"fancybox\" id=\"img-md5sum-ignore-missing\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/md5sum-ignore-missing.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-md5sum-command-tutorial-for-beginners-5-examples-3.png\" alt=\"How to make md5sum ignore missing files\" width=\"500\" height=\"106\" title=\"\"><\/a><\/p>\n<p>So you can see that the error and the notification wasn&#8217;t produced in the second case.<\/p>\n<h2 id=\"q-how-to-make-mdsum-avoid-printing-ok-for-each-successfully-verified-file\">Q4. How to make md5sum avoid printing OK for each successfully verified file?<\/h2>\n<p>Following is the default behavior of md5sum:<\/p>\n<p><a class=\"fancybox\" id=\"img-md5sum-c-option1\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/md5sum-c-option1.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/03\/linux-md5sum-command-tutorial-for-beginners-5-examples-4.png\" alt=\"How to make md5sum avoid printing OK for each successfully verified file\" width=\"416\" height=\"37\" title=\"\"><\/a><\/p>\n<p>However, if you do not want to see OK for each successfully verified file, you can use the <strong>&#8211;quiet<\/strong> option. So in our case, the above command would become:<\/p>\n<p class=\"command\">md5sum -c &#8211;quiet digest.md5<\/p>\n<h2 id=\"q-how-mdsum-computes-checksums\">Q5. How md5sum computes checksums?<\/h2>\n<p>The sums are computed by the tool as described in <a href=\"https:\/\/www.ietf.org\/rfc\/rfc1321.txt\" target=\"_blank\" rel=\"noopener noreferrer\">RFC 1321<\/a>. Here&#8217;s what the man page says:<\/p>\n<pre readability=\"12\"> The\u00a0 sums\u00a0 are\u00a0 computed\u00a0 as described in RFC 1321.\u00a0 When checking, the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 input should be a former output of this program.\u00a0 The default\u00a0 mode\u00a0 is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 to\u00a0 print\u00a0 a\u00a0 line with checksum, a space, a character indicating input<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mode ('*' for binary, ' ' for text or where binary\u00a0 is\u00a0 insignificant),<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 and name for each FILE.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The MD5 algorithm should not be used any more for security related pur?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 poses.\u00a0 Instead, better use an SHA-2 algorithm, implemented in the pro?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 grams sha224sum(1), sha256sum(1), sha384sum(1), sha512sum(1)<\/p><\/pre>\n<p>If you are a Linux command line newbie, there are fewer chances that you&#8217;ll use md5sum in your early days. It&#8217;s primarily aimed at system admins\/pro users. But there&#8217;s no harm in developing a basic understanding of how the tool works, which is precisely what this tutorial is focused at. In case you want to know more, you can head to md5sum&#8217;s <a href=\"https:\/\/linux.die.net\/man\/1\/md5sum\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>While we have already discussed the cksum command line utility, there&#8217;s another tool that you can use in scenarios where, say, you need to verify the integrity of files during transfers. The tool we&#8217;re talking about here is md5sum. In this tutorial, we will discuss the basics of this command using some easy to understand &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-3172","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=3172"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/3172\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=3172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=3172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=3172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}