Linux命令(109)之md5sum

linux命令之md5sum

1.md5sum介绍

linux命令md5sum是用来计算和校验文件的MD5值。

另外:

md5sum是用来校验文件内容,与文件名是否相同无关

md5sum校验文件时,逐位校验,如果文件越大,校验所需时间就越长

2.md5sum用法

md5sum [参数] filename

|----------|-----------------------------|
| 参数 | 说明 |
| -b | 以二进制模式读入文件内容 |
| -t | 以文本模式读入文件内容 |
| -c | 从指定文件中读取 MD5 校验和,并进行校验 |
| --status | 不生成[争取/错误]提示信息,通过命令返回值来判断 |
[md5sum参数]

3.实例

3.1.查看md5sum帮助信息

命令:

md5sum --help

复制代码
[root@rhel77 ~]# md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.

  -b, --binary         read in binary mode
  -c, --check          read MD5 sums from the FILEs and check them
      --tag            create a BSD-style checksum
  -t, --text           read in text mode (default)
  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.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'md5sum invocation'
[root@rhel77 ~]# 

3.2.检查文件md5值

命令:

md5sum -t ztj.txt

OR

md5sum -b ztj.txt

复制代码
root@rhel77 ~]# md5sum -t ztj.txt
cfc12d1432a7b067566080122b1c4f85  ztj.txt
[root@rhel77 ~]# md5sum -b ztj.txt
cfc12d1432a7b067566080122b1c4f85 *ztj.txt
[root@rhel77 ~]# 

3.3.检查文件md5值,与文件无关

命令:

\cp ztj.txt ztj.txt.bak

md5sum ztj.txt

md5sum ztj.txt.bak

复制代码
root@rhel77 ~]# \cp ztj.txt ztj.txt.bak
[root@rhel77 ~]# md5sum ztj.txt
cfc12d1432a7b067566080122b1c4f85  ztj.txt
[root@rhel77 ~]# md5sum ztj.txt.bak 
cfc12d1432a7b067566080122b1c4f85  ztj.txt.bak
[root@rhel77 ~]# 

3.4.从指定文件中读取MD5校验和,并进行校验

命令:

md5sum ztj.txt >> md5sum.txt

md5sum -c md5sum.txt

复制代码
[root@rhel77 ~]# md5sum ztj.txt >> md5sum.txt
[root@rhel77 ~]# 
[root@rhel77 ~]# md5sum -c md5sum.txt
ztj.txt: OK
[root@rhel77 ~]# 

3.5.从指定文件中读取MD5校验和,并不显示校验信息,以命令返回值来判断

备注:

如果校验一致返回0,不一致返回1

命令:

md5sum -c --status md5sum.txt

echo $?

复制代码
[root@rhel77 ~]# md5sum -c --status md5sum.txt
[root@rhel77 ~]# echo $?
0
[root@rhel77 ~]# 

OR

命令:

echo 111 >>ztj.txt

md5sum -c --status md5sum.txt

echo $?

复制代码
[root@rhel77 ~]# echo 111 >>ztj.txt
[root@rhel77 ~]# 
[root@rhel77 ~]# md5sum -c --status md5sum.txt
[root@rhel77 ~]# echo $?
1
[root@rhel77 ~]# 
相关推荐
绵绵细雨中的乡音6 分钟前
Linux进程学习【基本认知】
linux·运维·学习
Johny_Zhao24 分钟前
MySQL 高可用集群搭建部署
linux·人工智能·mysql·信息安全·云计算·shell·yum源·系统运维·itsm
lLinkl1 小时前
项目笔记2:post请求是什么,还有什么请求
服务器·网络协议·http
珹洺1 小时前
Linux操作系统从入门到实战(三)Linux基础指令(上)
linux·运维·服务器
再睡一夏就好1 小时前
Linux常见工具如yum、vim、gcc、gdb的基本使用,以及编译过程和动静态链接的区别
linux·服务器·c语言·c++·笔记
剁椒排骨1 小时前
win11什么都不动之后一段时间黑屏桌面无法显示,但鼠标仍可移动,得要熄屏之后才能进入的四种解决方法
运维·windows·经验分享·计算机外设·win11·win10
angushine1 小时前
让Docker端口映射受Firewall管理而非iptables
运维·docker·容器
归寻太乙2 小时前
Linux环境变量
linux·运维·服务器
m0Java门徒2 小时前
面向对象编程核心:封装、继承、多态与 static 关键字深度解析
java·运维·开发语言·intellij-idea·idea
Sapphire~2 小时前
Linux-06 ubuntu 系统截图软件使用简单记录
linux·运维·ubuntu