Linux命令(109)之md5sum

简介: 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 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 ~]#
————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/134111954

目录
相关文章
|
17天前
|
Linux
Linux系统之whereis命令的基本使用
Linux系统之whereis命令的基本使用
54 23
Linux系统之whereis命令的基本使用
|
3月前
|
Linux 网络安全 数据安全/隐私保护
Linux 超级强大的十六进制 dump 工具:XXD 命令,我教你应该如何使用!
在 Linux 系统中,xxd 命令是一个强大的十六进制 dump 工具,可以将文件或数据以十六进制和 ASCII 字符形式显示,帮助用户深入了解和分析数据。本文详细介绍了 xxd 命令的基本用法、高级功能及实际应用案例,包括查看文件内容、指定输出格式、写入文件、数据比较、数据提取、数据转换和数据加密解密等。通过掌握这些技巧,用户可以更高效地处理各种数据问题。
383 8
|
3月前
|
监控 Linux
如何检查 Linux 内存使用量是否耗尽?这 5 个命令堪称绝了!
本文介绍了在Linux系统中检查内存使用情况的5个常用命令:`free`、`top`、`vmstat`、`pidstat` 和 `/proc/meminfo` 文件,帮助用户准确监控内存状态,确保系统稳定运行。
1203 6
|
3月前
|
Linux
在 Linux 系统中,“cd”命令用于切换当前工作目录
在 Linux 系统中,“cd”命令用于切换当前工作目录。本文详细介绍了“cd”命令的基本用法和常见技巧,包括使用“.”、“..”、“~”、绝对路径和相对路径,以及快速切换到上一次工作目录等。此外,还探讨了高级技巧,如使用通配符、结合其他命令、在脚本中使用,以及实际应用案例,帮助读者提高工作效率。
229 3
|
3月前
|
监控 安全 Linux
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景
在 Linux 系统中,网络管理是重要任务。本文介绍了常用的网络命令及其适用场景,包括 ping(测试连通性)、traceroute(跟踪路由路径)、netstat(显示网络连接信息)、nmap(网络扫描)、ifconfig 和 ip(网络接口配置)。掌握这些命令有助于高效诊断和解决网络问题,保障网络稳定运行。
152 2
|
4天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
54 25
|
2天前
|
缓存 Linux
Linux查看内存命令
1. free free命令是最常用的查看内存使用情况的命令。它显示系统的总内存、已使用内存、空闲内存和交换内存的总量。 free -h • -h 选项:以易读的格式(如GB、MB)显示内存大小。 输出示例: total used free shared buff/cache available Mem: 15Gi 4.7Gi 4.1Gi 288Mi 6.6Gi 9.9Gi Swap: 2.0Gi 0B 2.0Gi • to
14 2
|
1月前
|
网络协议 Unix Linux
深入解析:Linux网络配置工具ifconfig与ip命令的全面对比
虽然 `ifconfig`作为一个经典的网络配置工具,简单易用,但其功能已经不能满足现代网络配置的需求。相比之下,`ip`命令不仅功能全面,而且提供了一致且简洁的语法,适用于各种网络配置场景。因此,在实际使用中,推荐逐步过渡到 `ip`命令,以更好地适应现代网络管理需求。
42 11
|
2月前
|
Linux Shell
Linux 10 个“who”命令示例
Linux 10 个“who”命令示例
117 14
Linux 10 个“who”命令示例
|
2月前
|
Ubuntu Linux
Linux 各发行版安装 ping 命令指南
如何在不同 Linux 发行版(Ubuntu/Debian、CentOS/RHEL/Fedora、Arch Linux、openSUSE、Alpine Linux)上安装 `ping` 命令,详细列出各发行版的安装步骤和验证方法,帮助系统管理员和网络工程师快速排查网络问题。
244 20