如何检查目录(整个文件夹)的md5sum和sha256sum?

J. *_*Doe 5 command-line directory md5sum sha256

在终端中很容易找到单个文件的 md5sum,但是整个目录的 md5sum 又如何呢?这同样适用于 sha256sum 吗?

Vid*_*uth 5

这个小脚本将对文件夹及其所有子文件夹进行 sha512sums 并将其保存到名为 sha512checksums 的文件中:

#!/bin/bash
rm -f sha512checksums
find -type f ! -iname "sha512checksums" -exec sha512sum "{}" + > sha512checksums
Run Code Online (Sandbox Code Playgroud)

下面的脚本可以让您根据之前创建的文件检查总和:

#!/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
Run Code Online (Sandbox Code Playgroud)

对于其他所有求和算法也同样有效,您只需更改脚本即可。