Linux md5sum 命令
Linux md5sum 命令
通过 Linux 的 md5sum 命令,可以对指定的文件,计算出唯一的一个MD5值(128bit)。
通过比较文件前后的MD5值,可以判断文件是否发生变化(是否被修改过)。
1、md5sum 命令使用方式(通过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) 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 character indicating input mode ('*' for binary, space for text), and name for each FILE. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'md5sum invocation'
2、计算一个文件的 MD5 值
1)新建一个文件test.txt,内容为 Hello, md5sum.
使用如下命令,生成改文件对应的 MD5 值:
md5sum test.txt > md5.out
2)此时会在当前目录下看到生成的 md5.out 文件
3)查看改文件对应的 MD5 值
cat md5.out
4)使用如下命令,比较文件的 MD5 值是否发生变化
md5sum -c md5.out
5)当修改test.txt 文件,增加 Modify 单词,再次对比 MD5 值,会发现不一致
6)BSD格式查看 MD5 值
md5sum --tag md5.out