This question already has an answer here:

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?

marked as duplicate by muru, Videonauth, Ron, Eric Carvalho, Parto Jun 15 '16 at 6:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


This little script will make sha512sums of a folder and all its subfolders and save it to a file called sha512checksums:

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:

rm -f sha512errors
sha512sum -c sha512checksums 2> sha512errors 1>/dev/null
if [ -s sha512errors ]
  echo The following errors where found while checking:
  more sha512errors
  rm -f sha512errors
  echo All files are ok.
  rm -f sha512errors

Same will work as well for every other sum making algorithm, you only would have to alter the scripts.

  • So when you said "every other sum making algorithm" you mean sha256sum also and not just sha512sum like you used? – J. Doe Jun 3 '16 at 8:33
  • 1
    md5sum, sha1sum till sha512sum, just alter the code accordingly. – Videonauth Jun 3 '16 at 8:35
  • Ahh. So is this the same method BitTorrent clients use when checking the integrity of a downloaded folder with contents inside? – J. Doe Jun 3 '16 at 8:37
  • Kinda, just a bash script to do the checking locally. – Videonauth Jun 3 '16 at 8:38
  • Does this actually output the filenames into the sha512errors file? My system only seems to output the number of failed files in STDOUT. – Arronical Jun 10 '16 at 11:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.