谷动谷力

 找回密码
 立即注册
查看: 1130|回复: 2
打印 上一主题 下一主题
收起左侧

【Shell命令】Linux获取文件MD5码命令md5sum浅析

[复制链接]
跳转到指定楼层
楼主
发表于 2023-10-19 17:42:02 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
【Shell命令】Linux获取文件MD5码命令md5sum浅析

概述

md5sum 用于计算和校验文件的MD5值。

md5sum 常常被用来验证网络文件传输的完整性,防止文件被人篡改。在日常工作当中,我们可以用来判断系统中的重要文件是否被篡改。传文件给别人时确认是否一致。

还可以使用使用 md5sum 生成文件或用户的密码。

语法

该命令的语法如下:

md5sum [选项] 文件
新命令老套路先help
  1. md5sum --help
  2. Usage: md5sum [OPTION]... [FILE]...
  3. Print or check MD5 (128-bit) checksums.

  4. With no FILE, or when FILE is -, read standard input.

  5.   -b, --binary         read in binary mode
  6.   -c, --check          read MD5 sums from the FILEs and check them
  7.       --tag            create a BSD-style checksum
  8.   -t, --text           read in text mode (default)

  9. The following five options are useful only when verifying checksums:
  10.       --ignore-missing  don't fail or report status for missing files
  11.       --quiet          don't print OK for each successfully verified file
  12.       --status         don't output anything, status code shows success
  13.       --strict         exit non-zero for improperly formatted checksum lines
  14.   -w, --warn           warn about improperly formatted checksum lines

  15.       --help     display this help and exit
  16.       --version  output version information and exit

  17. The sums are computed as described in RFC 1321.  When checking, the input
  18. should be a former output of this program.  The default mode is to print a
  19. line with checksum, a space, a character indicating input mode ('*' for binary,
  20. ' ' for text or where binary is insignificant), and name for each FILE.

  21. GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
  22. Full documentation at: <http://www.gnu.org/software/coreutils/md5sum>
  23. or available locally via: info '(coreutils) md5sum invocation'
复制代码

主要参数讲解
选项
说明
-b
以二进制模式读取文件
-t
以文本模式读入文件内容
-c
根据已生成的md5值,对现存文件进行校验
-w
检查输入的md5信息有没有非法行,若有则输出相应信息
–status
校验完成后,不生成错误或正确的提示信息,可以通过命令的返回值来判断

实例
  1. md5sum libnim.so
  2. 5ef2e45e1890736413407299ecc2786a  libnim.so
复制代码



+10

本帖被以下淘专辑推荐:

  • · Shell|主题: 28, 订阅: 0
回复

使用道具 举报

沙发
 楼主| 发表于 2023-10-19 20:19:02 | 只看该作者
生成文件md5值:
date | md5sum
ca85c81605f47386eae75781590ae2d3  -
+10
回复 支持 反对

使用道具 举报

板凳
发表于 2023-11-15 17:07:59 | 只看该作者
校验多个文件

如果要校验多个文件,命令格式如下:

# 语法md5sum 文件1 文件2 文件3 ...

# 示例
  1. md5sum test.txt two.txt one.txt
复制代码




+10
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-4-28 13:11 , Processed in 0.103466 second(s), 49 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表