当前位置: 首页 > news >正文

Linux命令(109)之md5sum

linux命令之md5sum

1.md5sum介绍

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

另外:

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

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

2.md5sum用法

md5sum [参数] filename

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

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 exitThe 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 ~]# 
http://www.lryc.cn/news/212361.html

相关文章:

  • JavaEE入门介绍,HTTP协议介绍,常用状态码及含义,服务器介绍(软件服务器、云服务器)
  • FPGA时序分析与约束(7)——通过Tcl扩展SDC
  • C++面试——多线程详解
  • matlab 布尔莎七参数坐标转换模型
  • Android---StartActivity启动过程
  • 隐私计算python实现Paillier同态加密
  • 代码随想录打卡第五十五天|● 300.最长递增子序列 ● 674. 最长连续递增序列 ● 718. 最长重复子数组
  • C# 创建Oceanbase ODBC数据源 DSN
  • C++ 常用函数汇总#include<algorithm>(3万字总结)
  • Google Archive Patch 基础应用代码记录
  • 机器学习——代价敏感错误率与代价曲线
  • 如何利用 ChatGPT 提升编程技能
  • ChatGPT:@EqualsAndHashCode(callSuper = false)是什么意思
  • docker部署的mariadb忘记密码
  • 一体化模型图像去雨+图像去噪+图像去模糊(图像处理-图像复原-代码+部署运行教程)
  • [java/力扣110]平衡二叉树——优化前后的两种方法
  • 吉他、班卓琴和贝斯吉他降分器:Arobas Music Guitar 8.1.1
  • cocos tilemap的setTileGIDAt方法不实时更新
  • 机器学习---使用 TensorFlow 构建神经网络模型预测波士顿房价和鸢尾花数据集分类
  • 铁合金电炉功率因数补偿装置设计
  • 表格识别软件:科技革新引领行业先锋,颠覆性发展前景广阔
  • 【Redis】高并发分布式结构服务器
  • 微信小程序拍照页面自定义demo
  • 单目标应用:进化场优化算法(Evolutionary Field Optimization,EFO)求解微电网优化MATLAB
  • 推荐算法面试
  • 长图切图怎么切
  • 动手学深度学习 - 学习环境配置
  • 洛谷 B2004 对齐输出 C++代码
  • seccomp学习 (1)
  • Linux指令【上】