Linux命令之md5sum
md5sum
md5sum用来计算一段内容的md5校验和,这段内容可以是从文件中读取的,也可以是从标准流输入的。甚至还可以将结果保存到文件,在以后使用这个文件来校验文件是否被改变。
需要注意的是md5sum只计算文件的内容,不关注文件的元信息。
简单使用
创建一个文件:
echo hello, world >> a.txt
计算它的md5检验和:
校验文件是否改变
可以把计算的结果存储到文件中,之后使用这个文件来校验文件是否发生了变化:
md5sum a.txt >> a.txt.md5sum
看下这个文件的内容:
使用这个文件来检查是否改变:
修改a.txt,追加一些内容:
再次检验:
从流读入
当不使用选项或者跟着-的时候,会从标准输入流stdin读取数据,可以使用流传递:
也可以手动输入,手动输入的时候使用Ctrl+D结束输入:
md5sum手册:
MD5SUM(1) User Commands MD5SUM(1) NAME md5sum - compute and check MD5 message digest SYNOPSIS md5sum [OPTION]... [FILE]... DESCRIPTION Print or check MD5 (128-bit) checksums. With no FILE, or when FILE is -, read standard input. -b, --binary read in binary mode -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) Note: There is no difference between binary and text mode option on GNU system. The following four 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 --strict exit non-zero for improperly formatted checksum lines -w, --warn warn about improperly formatted checksum lines --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 charac‐ ter indicating input mode ('*' for binary, space for text), and name for each FILE. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report md5sum translation bugs to <http://translationproject.org/team/> BUGS The MD5 algorithm should not be used any more for security related purposes. Instead, better use an SHA-2 algorithm, implemented in the programs sha224sum(1), sha256sum(1), sha384sum(1), sha512sum(1)
1. http://www.cnblogs.com/f-ck-need-u/p/7430264.html
.