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

目录
相关文章
|
20天前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
83 16
|
11天前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
|
2月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
657 13
|
3月前
|
Linux 网络安全 数据安全/隐私保护
使用Linux系统的mount命令挂载远程服务器的文件夹。
如此一来,你就完成了一次从你的Linux发车站到远程服务器文件夹的有趣旅行。在这个技术之旅中,你既探索了新地方,也学到了如何桥接不同系统之间的距离。
532 21
|
3月前
|
JSON 自然语言处理 Linux
linux命令—tree
tree是一款强大的Linux命令行工具,用于以树状结构递归展示目录和文件,直观呈现层级关系。支持多种功能,如过滤、排序、权限显示及格式化输出等。安装方法因系统而异常用场景包括:基础用法(显示当前或指定目录结构)、核心参数应用(如层级控制-L、隐藏文件显示-a、完整路径输出-f)以及进阶操作(如磁盘空间分析--du、结合grep过滤内容、生成JSON格式列表-J等)。此外,还可生成网站目录结构图并导出为HTML文件。注意事项:使用Tab键补全路径避免错误;超大目录建议限制遍历层数;脚本中推荐禁用统计信息以优化性能。更多详情可查阅手册mantree。
linux命令—tree
|
1月前
|
Linux 网络安全 开发工具
技术栈:这50条最常用的 Linux 命令你一定要会!
建议多在终端中实践,遇到不懂的命令就用 man 或 --help 了解详情!
381 0
|
3月前
|
监控 Linux
Linux系统中使用df命令详解磁盘使用情况。
`df`命令是Linux系统管理员和用户监控和管理磁盘空间使用的重要工具。掌握它的基本使用方法和选项可以帮助在必要时分析和解决空间相关问题。简洁但功能丰富,`df`命令确保了用户可以快速有效地识别和管理文件系统的空间使用情况。
249 13
|
1月前
|
安全 Linux Shell
Linux系统中sudo命令的高效运用技巧。
用户可以通过sudo -l来列出自己目前可执行的命令列表,这有助于用户了解自己的权限范围。
113 0
|
1月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
3月前
|
Unix Linux
linux命令—cd
`cd` 命令是 Linux/Unix 系统中用于切换工作目录的基础命令。支持相对路径与绝对路径,常用选项如 `-L` 和 `-P` 分别处理符号链接的逻辑与物理路径。实际操作中,可通过 `cd ..` 返回上级目录、`cd ~` 回到家目录,或利用 `cd -` 在最近两个目录间快速切换。结合 Tab 补全和 `pwd` 查看当前路径,能显著提升效率。此外,需注意特殊字符路径的正确引用及脚本中绝对路径的优先使用。