md5sum 的使用
1. 基本命令
$ md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.
-t, --text read in text mode (default)
-b, --binary read in binary mode
-c, --check read MD5 sums from the FILEs and check them
--tag create a BSD-style checksum
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.
2. 验证文件是否被篡改
把下载的文件file和该文件的file.md5报文摘要文件放在同一个目录下,然后用如下命令进行验证:
md5sum -c file.md5
md5sum命令还可以一次验证多个文件。如果将所需验证的文件名写入一个单独的文件,则可以使用该文件检查是否有任何文件已更改。
$ md5sum file1.txt file2.txt file3.txt > hashes
$ md5sum --check hashes
file1.txt: OK
file2.txt: OK
file3.txt: OK
3. 批量查看md5值
md5sum filename > filename.md5 # 创建单独的md5文件
md5sum *.filename > filename.md5 # 将所有文件的md5输入到一个文件中
# 让每个文件单独生成一个md5文件
for n in `ls *.fastq.gz`; do md5sum $n > ${n%.fastq.gz}.md5; done
# 创建sh文件用于批量运行
for n in `ls *.fastq.gz`; do echo "md5sum $n > ${n%.fastq.gz}.md5">>createmd5.sh; done
for n in `ls * R?.fq.gz`; do echo "md5sum $n > ${n%.fq.gz}.md5">>createmd5.sh; done