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

目录
相关文章
|
4天前
|
NoSQL 关系型数据库 MySQL
Linux学习记录---(1、基本命令)
该博客文章提供了Linux系统中基本命令的使用记录,包括文件和目录操作、Redis服务管理、MySQL数据库操作以及Tomcat服务器的启动和检查。
Linux学习记录---(1、基本命令)
|
5天前
|
运维 Ubuntu Linux
Linux系统之ncdu命令的基本使用
【8月更文挑战第8天】Linux系统之ncdu命令的基本使用
13 2
Linux系统之ncdu命令的基本使用
|
11天前
|
数据可视化 Linux 测试技术
7zip压缩工具的Linux命令
本文介绍了如何在Linux系统中使用7zip压缩工具,包括通过brew安装、使用基本命令进行文件压缩、解压、列出存档内容、测试存档完整性以及进行性能基准测试等操作。
45 3
7zip压缩工具的Linux命令
|
1天前
|
安全 Linux 开发者
Linux笔记之ldd命令详解
`ldd`命令是Linux环境下一个非常实用的工具,用于显示一个程序运行时所需的共享库依赖。它帮助开发者和系统管理员快速诊断程序运行问题,特别是在处理"找不到库文件"或者"错误的库文件版本"等错误时。然而,出于安全的考虑,对于不信任的可执行文件,应该慎用 `ldd`命令,可以考虑使用其他工具如 `objdump`。总的来说,懂得如何妥善且安全地使用 `ldd`,对于维护一个稳定和高效的Linux系统来说,是非常重要的。
16 9
|
2天前
|
Linux Shell
linux命令
linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。linux命令在系统中有两种类型:内置Shell命令和Linux命令。
|
3天前
|
移动开发 运维 网络协议
运维必备 | Linux netstat命令详解
运维必备 | Linux netstat命令详解
|
3天前
|
Linux
真香~ Linux vi常用命令汇总!
真香~ Linux vi常用命令汇总!
|
3天前
|
Linux Shell
linux命令
linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。linux命令在系统中有两种类型:内置Shell命令和Linux命令。
|
6天前
|
运维 安全 Linux
【超实用秘籍】Linux文件传输新高度:10个scp命令让你瞬间变身文件传输达人,从此告别繁琐操作!
【8月更文挑战第13天】文件传输是运维工作的核心部分,尤其对Linux用户来说,了解高效且安全的传输方法非常重要。本文介绍10种scp命令的应用技巧,涵盖基础文件传输、密钥认证、目录复制等场景,助你灵活运用这一基于SSH协议的安全工具。从简单的文件传输到复杂的多主机文件迁移,scp都能轻松应对。通过本文的学习,你将能更熟练地使用scp命令,提高工作效能。
25 6
|
2天前
|
SQL 存储 分布式计算
Linux退出Hive命令
【8月更文挑战第14天】