在linux下生成sha256校验文件
假设生成test.zip的文件的sha256校验文件:
//这里test.sha256sum就是要生成的文件
$ sha256sum.exe test.zip > test.sha256sum
校验某个文件sha256值
这个是最常用的功能了,一般下载某个镜像 都会给你带一个校验文件,那么怎么使用呢? SHA256SUMS:校验文件 deepin-desktop-community-23-amd64.iso: 镜像文件
//正确的验证 返回OK
$ sha256sum -c <(grep deepin-desktop-community-23-amd64.iso SHA256SUMS)
deepin-desktop-community-23-amd64.iso: OK
//如果验证失败,那文件有问题,不完整或者被动过手脚了
$ sha256sum -c <(grep deepin-desktop-community-23-amd64.iso a.sha256sum)
deepin-desktop-community-23-amd64.iso: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
注意:命令<
右侧不能有空格
命令 -c
代表从文件读取并校验sha256
$ sha256sum --help
Usage: sha256sum [OPTION]... [FILE]...
Print or check SHA256 (256-bit) checksums.
With no FILE, or when FILE is -, read standard input.
-c, --check read SHA256 sums from the FILEs and check them
--tag create a BSD-style checksum
这里注意SHA256SUMS文件可以包含多组校验值,意思是可以存储多个文件的校验值。一行一个。 内容格式:
校验值1 文件名1
校验值2 文件名2
//打开文件也可以看到
$ cat SHA256SUMS
fd0037372c58081ed68e244771c01b0a7b0cd921c5bf23301b8ab85299e1e94b deepin-desktop-community-23-amd64.iso
不难看出,要想确认某个文件的sha256校验值是否正确,只需要取出对应文件的校验值验证即可,因此,使用grep命令进行筛选出一行进行操作。