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

MD5校验:

magic@luna:~/lnmp$ md5sum lnmp1.3-full.tar.gz
a5aa55cd177cd9b9176ad697c12e45c0 lnmp1.3-full.tar.gz

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

magic@luna:~/lnmp$ md5sum lnmp1.3-full.tar.gz > md5-hash.txt

然后:

magic@luna:~/lnmp$ cat md5-hash.txt
a5aa55cd177cd9b9176ad697c12e45c0 lnmp1.3-full.tar.gz

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

magic@luna:~/lnmp$ md5sum -c md5-hash.txt
lnmp1.3-full.tar.gz: 确定
magic@luna:~/lnmp$

SHA1:

这个类似于MD5校验方法:

magic@luna:~/lnmp$ sha1sum lnmp1.3-full.tar.gz
ee7ec6e8be0b3b5a481df903427261236f9bb057 lnmp1.3-full.tar.gz

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

magic@luna:~/lnmp$ sha1sum lnmp1.3-full.tar.gz > sha1-hash.txt
magic@luna:~/lnmp$ cat sha1-hash.txt
ee7ec6e8be0b3b5a481df903427261236f9bb057 lnmp1.3-full.tar.gz

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

magic@luna:~/lnmp$ sha1sum -c sha1-hash.txt
lnmp1.3-full.tar.gz: 确定
magic@luna:~/lnmp$

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

magic@luna:~/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: <http://www.gnu.org/software/coreutils/>
请向<http://translationproject.org/team/zh_CN.html> 报告sha1sum 的翻译错误
Full documentation at: <http://www.gnu.org/software/coreutils/sha1sum>
or available locally via: info '(coreutils) sha1sum invocation'

ps:转载请注明文章出处。

linux中校验文件完整性(md5,sha1)的更多相关文章

  1. Linux md5sum校验文件完整性

    使用场景:  远程备份大文件,防止网络异常断开,文件备份不完整,使用md5校验其完整性. 1. 获取文件md5值 [root@kvm-123 gitlab]# md5sum 1564248991_20 ...

  2. mac上校验文件的 md5 sha-1

    文件校验 mac md5 sha-1html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMir ...

  3. Linux下查询文件的md5,sha1值

    验证下载下来的文件包是不是一致 ··· 验证md5值 #md5sum filename 验证shal值 #sha1sum filename ···

  4. Linux下校验下载文件的完整性(MD5,SHA1,PGP)

    查看: Linux下校验下载文件的完整性(MD5,SHA1,PGP) http://blog.useasp.net/archive/2014/03/29/use-md5-sha1-or-pgp-to- ...

  5. Shell 对整个文件夹中的文件进行MD5校验 [转]

    查看本地文件的 MD5 命令:md5sum FileName查看home目录下所有文件的 MD5 码:cd ~find /home -type f -print0 | xargs -0 md5sum ...

  6. Hash校验工具、MD5 SHA1 SHA256命令行工具

    MyHash 检验工具http://www.zdfans.com/html/4346.html HashMyFiles Hash校验工具http://www.nirsoft.net/utils/has ...

  7. 【转】linux中inittab文件详解

    原文网址:http://www.2cto.com/os/201108/98426.html linux中inittab文件详解 init的进程号是1(ps -aux | less),从这一点就能看出, ...

  8. Linux中检索文件

    1 , Use locate command It is a fast way to find the files location, but if a file just created ,it w ...

  9. Linux中查看文件编码

    在Linux中查看文件编码可以通过以下几种方式:1.在Vim中可以直接查看文件编码:set fileencoding即可显示文件编码格式.如果你只是想查看其它编码格式的文件或者想解决用Vim查看文件乱 ...

随机推荐

  1. code3027 线段覆盖2

    dp 数据:d[i].a d[i].b d[i].v 分别表示第i条线段的起始点,结束点,价值 先按d[i].b排好序 dp[i]表示前i条线段的最大价值 方程: dp[i]=max{ dp[i-1] ...

  2. phpmailer配置qq邮箱

    function send_email2($email = '*****@perspectivar.com'){ $this->autoRender = false; date_default_ ...

  3. TIMER_PWM_CAPTURE

  4. [GO]用go语言实现区块链工作原理

    基本原理这里就不写了,只写一个简单demo的实现 首先得有一个区块用来存储区块头和区块体 type Block struct { Version int64 PreBlockHash []byte H ...

  5. QT学习之窗口部件

    对话框--QDialog 模态对话框与非模态对话框 模态对话框:就是相当于没关闭它之前,不能再和该应用程序的其他窗口进行交互(比如新建项目时弹出的对话框) 非模态对话框:可以与它交互,也可以与该程序中 ...

  6. Memory Analysis Part 1 – Obtaining a Java Heapdump

    转自: https://blog.codecentric.de/en/2008/07/memory-analysis-part-1-obtaining-a-java-heapdump/ For tro ...

  7. C++中的类型判断typeid()操作与java中的 instanceof 做比较

    这是RTTI(运行阶段类型识别)的问题,c++有三个支持RTTI的元素: 1. dynamic_cast 操作符     如果可能的话,dynamic_cast操作符将使用一个指向基类的指针来生成一个 ...

  8. c_c++基础问题(平时读书时笔记)

    1 IP私有地址: 10.0.0.0 -- 10.255.255.255 172.16.0.0 -- 172.31.255.255 192.168.0.0 -- 192.168.255.255 2OS ...

  9. phpize命令在安装AMQP插件是报错phpize:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF envir的解决方法

    phpize命令在安装AMQP插件是报错phpize:Cannot find autoconf. Please check your autoconf installation and the $PH ...

  10. xshell无法连接Ubuntu的解决办法

    使用workstations14安装完Ubunu后,网络连接方式为NAT模式(N):用于共享主机的IP地址 此时想用xshell连接此虚拟机但是提示连接失败,但是宿主机和虚拟机互相都能ping通,且虚 ...