How to check the md5sum and sha256sum of a directory (an entire folder)?
11,354
This little script will make sha512sums of a folder and all its subfolders and save it to a file called sha512checksums:
#!/bin/bash
rm -f sha512checksums
find -type f ! -iname "sha512checksums" -exec sha512sum "{}" + > sha512checksums
And this following scrip lets you check the sums based on the before created file:
#!/bin/bash
rm -f sha512errors
sha512sum -c sha512checksums 2> sha512errors 1>/dev/null
if [ -s sha512errors ]
then
echo The following errors where found while checking:
more sha512errors
rm -f sha512errors
else
echo All files are ok.
rm -f sha512errors
fi
Same will work as well for every other sum making algorithm, you only would have to alter the scripts.
Related videos on Youtube
Author by
J. Doe
Updated on September 18, 2022Comments
-
J. Doe almost 2 years
In the terminal it's easy to find the md5sum of a single file, but how about for an entire directory? And would the same apply to sha256sum?
-
J. Doe about 8 yearsSo when you said "every other sum making algorithm" you mean sha256sum also and not just sha512sum like you used?
-
Videonauth about 8 years
md5sum
,sha1sum
tillsha512sum
, just alter the code accordingly. -
J. Doe about 8 yearsAhh. So is this the same method BitTorrent clients use when checking the integrity of a downloaded folder with contents inside?
-
Videonauth about 8 yearsKinda, just a bash script to do the checking locally.
-
Arronical about 8 yearsDoes this actually output the filenames into the sha512errors file? My system only seems to output the number of failed files in STDOUT.
-
Videonauth about 8 yearsthe file only will contain errors, if there are no errors the file will be empty, and anyways removed at the end.
-
Videonauth about 8 yearsIf you want output leave the
1>/dev/null
out