{"id":512,"date":"2012-10-07T12:16:14","date_gmt":"2012-10-07T11:16:14","guid":{"rendered":"http:\/\/www.nooblet.org\/blog\/?p=512"},"modified":"2013-01-10T04:29:16","modified_gmt":"2013-01-10T04:29:16","slug":"create-md5-checksum-files-for-each-sub-directory","status":"publish","type":"post","link":"https:\/\/www.nooblet.org\/blog\/2012\/create-md5-checksum-files-for-each-sub-directory\/","title":{"rendered":"Create md5 checksum files for each sub-directory"},"content":{"rendered":"<p>This bash script creates checksum files for each subdirectory and the files within.<\/p>\n<p>If the script is run, and there are no changes, then there is no output. This makes it safe to put into a cronjob without fear of getting spammed.<\/p>\n<p>Output can be forced with a &#8220;-d&#8221; flag.<\/p>\n<p><strong>Requires &#8220;md5sum&#8221; package to compute checksums.<\/strong><\/p>\n<p>Syntax:<br \/>\n<code>md5-all-dir.sh [-d] &lt;directory&gt;<\/code><\/p>\n<p><strong>Download<\/strong><br \/>\n<div class=\"wp-downloadmanager\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"wp-downloadmanager-sprite\" aria-hidden=\"true\" focusable=\"false\"><symbol id=\"wp-downloadmanager-icon-file\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-archive\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M11 3h2v2h-2zM11 6h2v2h-2zM11 9h2v2h-2zM10.5 13h3v3.5h-3z\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-audio\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M10 18.5v-5l5-1.5v5\" \/><circle cx=\"9\" cy=\"18.5\" r=\"1.4\" \/><circle cx=\"14\" cy=\"17\" r=\"1.4\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-code\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M10.5 12.5 8 15.5l2.5 3M13.5 12.5 16 15.5l-2.5 3\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-document\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M9 12.5h6M9 15.5h6M9 18.5h4\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-image\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><circle cx=\"10\" cy=\"13.5\" r=\"1.1\" \/><path d=\"M8 19.5l3-3 2 2 3-3.5 2 4.5z\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-presentation\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M9 19.5v-3M12 19.5v-5.5M15 19.5v-8\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-spreadsheet\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M8 12.5h8v7H8zM8 16h8M11.5 12.5v7\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-video\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><path d=\"M10.5 13.5l5 3-5 3z\" \/><\/symbol><symbol id=\"wp-downloadmanager-icon-application\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M6 2.5h7l5 5v14H6z\" \/><path d=\"M13 2.5v5h5\" \/><circle cx=\"12\" cy=\"16.5\" r=\"2\" \/><path d=\"M12 12.5V14M12 19v1.5M8.5 16.5H10M14 16.5h1.5\" \/><\/symbol><\/svg><svg class=\"wp-downloadmanager-icon\" aria-hidden=\"true\" focusable=\"false\"><use href=\"#wp-downloadmanager-icon-file\" \/><\/svg>&nbsp;&nbsp;<strong><a href=\"https:\/\/www.nooblet.org\/blog\/download\/md5-all-dir.sh\">md5-all-dir.sh<\/a><\/strong> (4.1 KiB, 3,011 hits)<br><\/div><br \/>\n<!--more--><\/p>\n<p>For example, say you have the following directory structure<\/p>\n<blockquote><p><code>$ tree<br \/>\n.<br \/>\n\u251c\u2500\u2500 a<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 1<br \/>\n\u251c\u2500\u2500 b<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 1<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 2<br \/>\n\u2514\u2500\u2500 c<br \/>\n    \u251c\u2500\u2500 1<br \/>\n    \u251c\u2500\u2500 2<br \/>\n    \u2514\u2500\u2500 3<\/p>\n<p>3 directories, 6 files<\/code><\/p><\/blockquote>\n<p>This script will create a checksum file for directories &#8220;a&#8221;, &#8220;b&#8221; and &#8220;c&#8221;.<\/p>\n<blockquote><p><code>$ md5-all-dir .\/<br \/>\n ! Looping .\/ ..<br \/>\n o .\/c<br \/>\n   - newfile: 1<br \/>\n   - newfile: 2<br \/>\n   - newfile: 3<br \/>\n o .\/b<br \/>\n   - newfile: 1<br \/>\n   - newfile: 2<br \/>\n o .\/a<br \/>\n   - newfile: 1<\/code><\/p><\/blockquote>\n<p>So now the directory structure is:<\/p>\n<blockquote><p><code>$ tree<br \/>\n.<br \/>\n\u251c\u2500\u2500 a<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 1<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 a-checksums.md5<br \/>\n\u251c\u2500\u2500 b<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 1<br \/>\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 2<br \/>\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 b-checksums.md5<br \/>\n\u2514\u2500\u2500 c<br \/>\n    \u251c\u2500\u2500 1<br \/>\n    \u251c\u2500\u2500 2<br \/>\n    \u251c\u2500\u2500 3<br \/>\n    \u2514\u2500\u2500 c-checksums.md5<\/p>\n<p>3 directories, 9 files<\/code><\/p><\/blockquote>\n<p>Each checksum file has the following structure:<\/p>\n<blockquote><p><code>$ cat .\/c\/c-checksums.md5<br \/>\n; Checksum created on Thu Jan 10 04:26:40 GMT 2013<br \/>\n; by stalks@sith.nooblet.org (\/usr\/local\/bin\/md5-all-dir)<br \/>\n; for \/tmp\/test\/c<\/p>\n<p>; data 1349606635 1349606635 10240 e91ce12bd9ee7bdeca70774f7b5fbea4 1<br \/>\ne91ce12bd9ee7bdeca70774f7b5fbea4 *1<br \/>\n; data 1349606641 1349606641 10240 e266420d33efae6d9f7e5e8804c48ed6 2<br \/>\ne266420d33efae6d9f7e5e8804c48ed6 *2<br \/>\n; data 1349606642 1349606642 10240 18ce779ed5275775f80053de68753cb5 3<br \/>\n18ce779ed5275775f80053de68753cb5 *3<\/p>\n<p>; Time taken: 1 secs<\/code><\/p><\/blockquote>\n<p>The data line holds creation time, modified time, file size, md5sum and filename, and is used by the script to determine if any files have changed.<\/p>\n<p>If the script is run again, it will parse the checksum files and update for any missing\/modified\/new files.<\/p>\n<p>For example, if I add &#8220;a\/testfile&#8221;:<\/p>\n<blockquote><p><code>$ touch .\/a\/testfile<br \/>\n$ md5-all-dir .\/<br \/>\n ! Looping .\/ ..<br \/>\n o .\/c<br \/>\n o .\/b<br \/>\n o .\/a<br \/>\n   - newfile: testfile<\/code><\/p><\/blockquote>\n<p><strong>Download<\/strong><br \/>\n<div class=\"wp-downloadmanager\"><svg class=\"wp-downloadmanager-icon\" aria-hidden=\"true\" focusable=\"false\"><use href=\"#wp-downloadmanager-icon-file\" \/><\/svg>&nbsp;&nbsp;<strong><a href=\"https:\/\/www.nooblet.org\/blog\/download\/md5-all-dir.sh\">md5-all-dir.sh<\/a><\/strong> (4.1 KiB, 3,011 hits)<br><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This bash script creates checksum files for each subdirectory and the files within. If the script is run, and there are no changes, then there is no output. This makes it safe to put into a cronjob without fear of getting spammed. Output can be forced with a &#8220;-d&#8221; flag. Requires &#8220;md5sum&#8221; package to compute [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":648,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[27,36,233,104],"class_list":["post-512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-bash","tag-checksum","tag-linux","tag-md5"],"_links":{"self":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":2,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":661,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/512\/revisions\/661"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/media\/648"}],"wp:attachment":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}