BSD md5 与 GNU md5sum 输出格式?
任何人都知道为什么 BSD md5 程序会产生这种格式的哈希输出……
MD5 (checksum.md5) = 9eb7a54d24dbf6a2eb9f7ce7a1853cd0
而 GNU md5sum 会产生这样更合理的格式?
9eb7a54d24dbf6a2eb9f7ce7a1853cd0 checksum.md5
据我所知,md5sum 格式更容易解析并且更有意义。 如何使用 md5 进行md5sum -check
? -p、-q、-r、-t、-x 选项是什么意思? man md5
没有提及这些选项! :|
Any one knows why BSD md5 program produces hash output in this format ...
MD5 (checksum.md5) = 9eb7a54d24dbf6a2eb9f7ce7a1853cd0
... while GNU md5sum produces much more sensible format like this?
9eb7a54d24dbf6a2eb9f7ce7a1853cd0 checksum.md5
As far as I can tell, the md5sum format is much easier to parse and makes more sense. How do you do md5sum -check
with md5? And what do the -p, -q, -r, -t, -x options mean? man md5
says nothing about those options! :|
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在当前的 OS X BSD 系统上,您可以指定 md5 -r 命令来获取预期的输出。
添加 md5 -r 开关使输出看起来更像我所期望的,并且更容易与 Linux 机器生成的 linux md5 和进行比较。
对我来说,这是最简单的方法,很容易与 Linux 机器上的 md5sum 命令生成的输出进行区分。
On current OS X BSD systems you can specify the md5 -r command to get the expected output.
Adding the md5 -r switch made the output look more like I was expecting, and easier to diff with the linux md5 sums that were produced from a Linux machine.
This was the simplest approach for me to make is easy to diff from output generated by the md5sum command on a linux box.
我猜是历史原因。 同时, -q 抑制 "MD5(...) = " 输出,因此 md5 -q checksum.md5 给出
如果 md5 没有给出任何参数并且它从 stdin 读取,则暗示这一点。
不幸的是,在这种情况下,md5sum 在校验和后面留下了“-”(“9eb7a54d24dbf6a2eb9f7ce7a1853cd0 -”),
因此,如果您正在寻找一些通用函数来返回校验和,以下内容可能会有所帮助:
FreeBSD 的手册页介绍了这些参数
Historical reasons, i guess. Meanwhile, -q suppress "MD5(...) = " output, so md5 -q checksum.md5 gives
This is implied if md5 is not given any arguments and it reads from stdin.
Unfortunately md5sum in this case leaves "-" behind the checksum ("9eb7a54d24dbf6a2eb9f7ce7a1853cd0 -"),
so if you're looking for some generic function to return the checksum, here is what might help:
FreeBSD's man page says about the arguments
我意识到这是一个旧页面,但我在 FreeBSD 上进行校验并在 Linux 上检查它们,我也遇到了这个页面。 这个页面没有帮助我解决问题,所以我想出了这个小
sed
脚本来在 FreeBSD 上创建与 Linuxmd5sum
输出匹配的校验和:这将使用FreeBSD
md5
命令并重新排列输出,使其看起来像 GNUmd5sum
。然后在 Linux 上我可以使用
md5sum --check md5sums.txt
您还可以将上面的
sed
脚本与 FreeBSD 的md5
命令。我还将这个别名放入我的 FreeBSD .cshrc 文件中:
现在在 FreeBSD 上我只需说
md5sum file1 file2 file3 ...
就可以了。I realize this is an old page, but I was making checksums on FreeBSD and checking them on Linux and I came across this page too. This page didn't help me solve the problem, so I came up with this small
sed
script to create the checksums on FreeBSD that match the Linuxmd5sum
output:This will use the FreeBSD
md5
command and rearrange the output to look like the GNUmd5sum
.Then on Linux I can just use
md5sum --check md5sums.txt
You can also use the above
sed
script with an existing file produced by FreeBSD'smd5
command.I also put this alias in my FreeBSD .cshrc file:
now on FreeBSD I can just say
md5sum file1 file2 file3 ...
and it just works.可以使用 GNU
md5sum -c checksum.md5
来查找checksum
文件并检查checksum.md5
文件内容。md5sum -c 校验和.md5 | grep "checksum: OK" -
Ruby 系统调用中的示例,用于检查 BSD 格式的 .md5 文件:
system("md5sum -c checksum.md5 | grep \"checksum: OK\" -" )
这将返回 true 或 false。
One can use the GNU
md5sum -c checksum.md5
that will look forchecksum
file and check against thechecksum.md5
file content.md5sum -c checksum.md5 | grep "checksum: OK" -
Example inside a Ruby system call to check against a BSD formatted .md5 file:
system("md5sum -c checksum.md5 | grep \"checksum: OK\" -")
This will return true or false.