来自终端的 sha512sum 是错误的

来自终端的 sha512sum 是错误的

润宁

回声“zyc.txt”| openssl dgst -sha512

(标准输入)= 11aa472bf4c97ffb1fae06a3f7175127da084c5dfb840038ee308b37136330e5b6a56cc053c62881f10aec88948d8addb1d4844496cdb08e4067b4fd460133 0e

或者

回声“zyc.txt”| sha512sum 11aa472bf4c97ffb1fae06a3f7175127da084c5dfb840038ee308b37136330e5b6a56cc053c62881f10aec88948d8addb1d4844496cdb08e4067b4fd46013 30e

输出错误,hash 应该是

DDD2379F9A1ADF4F0AFA0BEFAFDB070FB942D4D4E0331A31D43494149307221E5E699DA2A08F59144B​​0ED415DEA6F920CF3DAB8CA0B740D874564D83B9B6F815

这是我电脑上的信息

Linux MobileSpace 4.14.0-3-amd64 #1 SMP Debian 4.14.17-1 (2018-02-14) x86_64 GNU/Linux

sha512sum --version
sha512sum (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Ulrich Drepper, Scott Miller, and David Madore.

这是一个错误还是我做错了?

答案1

Echo 附加一个换行符,您可以使用 -n 抑制它:

echo -n "zyc.txt" | sha512sum 
ddd2379f9a1adf4f0afa0befafdb070fb942d4d4e0331a31d43494149307221e5e699da2a08f59144b0ed415dea6f920cf3dab8ca0b740d874564d83b9b6f815  -

大多数时候,您喜欢换行符,因此您的提示位于下一行的开头,而不是在最后一个输出行的中间。

上厕所时也必须记住这一点:

echo -n "zyc.txt" | wc
      0       1       7
echo "zyc.txt" | wc
      1       1       8

相关内容