版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010168781/article/details/84102616
1、命令详解
$ md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.
-b, --binary read in binary mode
-c, --check read MD5 sums from the FILEs and check them
--tag create a BSD-style checksum
-t, --text read in text mode (default)
The following three options are useful only when verifying checksums:
--quiet don't print OK for each successfully verified file
--status don't output anything, status code shows success
-w, --warn warn about improperly formatted checksum lines
--strict with --check, exit non-zero for any invalid input
--help display this help and exit
--version output version information and exit
The sums are computed as described in RFC 1321. 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.
Report md5sum bugs to [email protected]
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'md5sum invocation'
-b, --binary:以二进制方式读取文件
-t, --text :默认配置,以文本方式读取文件
这两种方式的输出结果相同,测试例子如下:
$ md5sum hello.c
6a29375b3e989a04355ecee250448c6e hello.c
$ md5sum -b hello.c
6a29375b3e989a04355ecee250448c6e *hello.c
$ md5sum a.out
40a9477fa25a9df86361571dd60feffc a.out
$ md5sum -b a.out
40a9477fa25a9df86361571dd60feffc *a.out
-c, --check:从指定文本中读取md5值,然后检测MD5值对应的文件是否完整,这个“指定文本”的格式如下:
40a9477fa25a9df86361571dd60feffc a.out
就是在计算文件MD5值时的输出结果,使用例子如下:
$ md5sum a.out > md5.txt
$ cat md5.txt
40a9477fa25a9df86361571dd60feffc a.out
$ md5sum -c md5.txt
a.out: OK
当检查出错误时的打印信息如下
$ md5sum -c md5.txt
a.out: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
–tag:安装BSD样式输出结果
$ md5sum --tag a.out
MD5 (a.out) = 40a9477fa25a9df86361571dd60feffc
下面三个选项,只有在检查MD5值(-c)时有效,即和-c一起使用,否则会报错:
$ md5sum --quiet md5.txt
md5sum: the --quiet option is meaningful only when verifying checksums
Try 'md5sum --help' for more information.
–quiet:如果检查MD5值成功,不再打印OK
$ md5sum -c md5.txt
a.out: OK
//成功时没有输出:
$ md5sum --quiet -c md5.txt
//失败才打印,错误信息
$ md5sum -c md5.txt
a.out: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
$ md5sum --quiet -c md5.txt
a.out: FAILED
md5sum: WARNING: 1 computed checksum did NOT match
–status:不打印任何信息,执行结果以状态码形式输出
//失败情况
$ md5sum --status -c md5.txt
$ echo $?
1
//成功情况
$ md5sum --status -c md5.txt
$ echo $?
0
-w, --warn :如果检测文本中有,非法的行,不符合md5sum -c需要的格式,则打印出警告信息
$ md5sum --warn -c md5.txt
a.out: OK
md5sum: md5.txt: 2: improperly formatted MD5 checksum line
md5sum: WARNING: 1 line is improperly formatted
–strict:对于无效的输入,都返回非零状态(不知道怎么用)
–help:帮助信息
–version:版本信息