linux验证文件的完整性,linux中校验文件完整性(md5,sha1)(示例代码)

经常在Linux下下载软件的人,一定会有一个良好的习惯:校验文件的hash,以确定文件的完整性甚至是安全性。我配置环境的时候也恰好用到了,笔者的是一个lubuntu的机子。这里我大致做个记录。(不了解hash的请自行查阅相关资料)

MD5校验:

[email protected]:~/lnmp$ md5sum lnmp1.3-full.tar.gz

a5aa55cd177cd9b9176ad697c12e45c0 lnmp1.3-full.tar.gz

或者我们可以保存到一个文件中:

[email protected]:~/lnmp$ md5sum lnmp1.3-full.tar.gz > md5-hash.txt

然后:

[email protected]:~/lnmp$ cat md5-hash.txt

a5aa55cd177cd9b9176ad697c12e45c0 lnmp1.3-full.tar.gz

还可以根据已经得到的hash来确认文件:

[email protected]:~/lnmp$ md5sum -c md5-hash.txt

lnmp1.3-full.tar.gz: 确定

[email protected]:~/lnmp$

SHA1:

这个类似于MD5校验方法:

[email protected]:~/lnmp$ sha1sum lnmp1.3-full.tar.gz

ee7ec6e8be0b3b5a481df903427261236f9bb057 lnmp1.3-full.tar.gz

或者保存到文件中再去查看:

[email protected]:~/lnmp$ sha1sum lnmp1.3-full.tar.gz > sha1-hash.txt

[email protected]:~/lnmp$ cat sha1-hash.txt

ee7ec6e8be0b3b5a481df903427261236f9bb057 lnmp1.3-full.tar.gz

已知hash情况下的校验(通常这个情况还挺多):

[email protected]:~/lnmp$ sha1sum -c sha1-hash.txt

lnmp1.3-full.tar.gz: 确定

[email protected]:~/lnmp$

注意事项:在已知hash数值情况下对文件进行校验的时候要注意,一定要让系统能够找到要校验的文件。否则就没法进行校验了。具体的使用说明,可以通过md5(sha1)sum --help来查看:

[email protected]:~/lnmp$ sha1sum --help

Usage: sha1sum [OPTION]... [FILE]...

Print or check SHA1 (160-bit) checksums.

如果没有指定文件,或者文件为"-",则从标准输入读取。

-b, --binary read in binary mode

-c, --check从文件中读取SHA1 的校验值并予以检查

--tag create a BSD-style checksum

-t, --text以纯文本模式读取(默认)

The following five options are useful only when verifying checksums:

--ignore-missing don‘t fail or report status for missing files

--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显示此帮助信息并退出

--version显示版本信息并退出

The sums are computed as described in FIPS-180-1. When checking, the input

should be a former output of this program. The default mode is to print a

line with checksum, a space, a character indicating input mode (‘*‘ for binary,

‘ ‘ for text or where binary is insignificant), and name for each FILE.

GNU coreutils online help:

请向 报告sha1sum 的翻译错误

Full documentation at:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值