如何自动比较大量文件的 md5sum 哈希值

sou*_* c. 39 command-line md5sum

我可以从终端检查文件的 md5sum 哈希值,

$ md5sum my_sensitive_file
8dad53cfc973c59864b8318263737462 my_sensitive_file
Run Code Online (Sandbox Code Playgroud)

但困难的部分是将哈希值与精确值进行比较。

对于大量文件,很难将 32 个字符输出与任何人的原始/精确哈希值进行比较。首先,工作会很单调,错误范围也很大。

是否可以自动化比较过程,最好是在 CLI 中?

c0r*_*0rp 49

例如,我有一个名为test_binary.

文件测试的MD5总和是 ef7ab26f9a3b2cbd35aa3e7e69aad86c

要自动测试它,请运行:

$ md5sum -c <<<"ef7ab26f9a3b2cbd35aa3e7e69aad86c *path/to/file/test_binary"
test_binary: OK
Run Code Online (Sandbox Code Playgroud)

或者

$ echo "595f44fec1e92a71d3e9e77456ba80d1  filetohashA.txt" | md5sum -c -
Run Code Online (Sandbox Code Playgroud)

来自男人的报价

   -c, --check
          read MD5 sums from the FILEs and check them
Run Code Online (Sandbox Code Playgroud)

来自维基的引用

注意:每个 md5sum 值和要比较的文件名之间必须有两个空格。否则,将导致以下错误:“找不到格式正确的 MD5 校验和行”。

维基链接

你也可以从文件中读取 md5 哈希值

$ md5sum -c md5sum_formatted_file.txt
Run Code Online (Sandbox Code Playgroud)

它期望文件格式为:

<md5sum_checksum><space><space><file_name>
Run Code Online (Sandbox Code Playgroud)

关于MD5 sum 哈希*<space>之后。人中有一点注意事项:

 When  checking,  the
       input  should  be a former output of this program.  The default mode is
       to print a line with checksum, a character indicating input  mode  ('*'
       for binary, space for text), and name for each FILE.
Run Code Online (Sandbox Code Playgroud)

这里是stackoverflow 的链接,我在那里找到了问题的答案,为什么我们有时要区分binary文件和text文件。


  • 星号是必须的吗? (3认同)