1.shasum介绍
linux命令shasum用于核实文件传输结束后的完整性。通常在网络传输文件的过程中,可能造成文件丢失,所以可以用来检查文件传输是否完整。
2.shasum用法
shasum [参数] [file]
[root@elasticsearch ztj]# shasum -h
Usage: shasum [OPTION]... [FILE]...
Print or check SHA checksums.
With no FILE, or when FILE is -, read standard input.
-a, --algorithm 1 (default), 224, 256, 384, 512, 512224, 512256
-b, --binary read in binary mode
-c, --check read SHA sums from the FILEs and check them
-t, --text read in text mode (default)
-p, --portable read in portable mode
produces same digest on Windows/Unix/Mac
-0, --01 read in BITS mode
ASCII '0' interpreted as 0-bit,
ASCII '1' interpreted as 1-bit,
all other characters ignored
The following two options are useful only when verifying checksums:
-s, --status don't output anything, status code shows success
-w, --warn warn about improperly formatted checksum lines
-h, --help display this help and exit
-v, --version output version information and exit
When verifying SHA-512/224 or SHA-512/256 checksums, indicate the
algorithm explicitly using the -a option, e.g.
shasum -a 512224 -c checksumfile
The sums are computed as described in FIPS-180-4. 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 type (`*' for binary,
` ' for text, `?' for portable, `^' for BITS), and name for each FILE.
Report shasum bugs to mshelor@cpan.org
[root@elasticsearch ztj]#
3.shasum样例
命令:
shasum -a 512 -c elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512
#检查elasticsearch-7.11.1传输后的完整性
[root@elasticsearch ~]# cat elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512
49db18ecb8c67dd904106165f599d5757f5ce3cdbe5835e8d4babf85f5274368b45fb6bbaf23350107305904ea1823d929444858cf3df686df3c52e8506ce569 elasticsearch-7.11.1-linux-x86_64.tar.gz
[root@elasticsearch ~]# shasum -a 512 -c elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512
elasticsearch-7.11.1-linux-x86_64.tar.gz: OK
[root@elasticsearch ~]#
命令:
shasum -a 512 aaa >aaa.sha512
shasum -a 512 -c aaa.sha512
[root@elasticsearch ztj]# shasum -a 512 aaa >aaa.sha512
[root@elasticsearch ztj]# shasum -a 512 -c aaa.sha512
aaa: OK
[root@elasticsearch ztj]#
#创建自定义文件shasum,并进行校验(文件传输后,如果传输后,文件内容有变化,校验会失败)
[root@elasticsearch ztj]# echo aa > aaa
[root@elasticsearch ztj]# shasum -a 512 -c aaa.sha512
aaa: FAILED
shasum: WARNING: 1 computed checksum did NOT match
[root@elasticsearch ztj]#