Bash 的 md5sum 命令

作者:hubenchang0515日期:2025/11/6

#Bash 的 md5sum 命令

1md5sum [OPTION]... [FILE]... 2

功能

计算或校验 MD5 值。

类型

可执行文件(/usr/bin/md5sum),属于 coreutils

参数

  • OPTION 选项:
    • -b, --binary - 以二进制模式读取文件;类 UNIX 系统下始终是二进制模式
    • -c, --check - 从文件中读取 MD5 值进行校验
    • --tag- 生成 BSD 风格的输出
    • -t, --text - 以文本模式读取文件;类 UNIX 系统下不存在文本模式,此选项无效
    • -z, --zero - 以空字符(\0)作为行的结尾,而不是换行符(\n
    • --ignore-missing - 校验时忽略缺失的文件
    • --quiet - 校验时不打印成功的消息
    • --status - 校验时不打印任何消息;可以通过返回值检查是否成功
    • --strict - 校验时严格检查格式
    • -w, --warn - 校验时遇到格式不正确的行时产生警告
    • --help - 显示帮助
    • --version - 显示版本
  • FILE - 文件列表

#示例

计算 MD5 值

1$ md5sum 1.txt # 单个文件 279171af5e65e23a97b58c343c4de7411 1.txt 3$ md5sum 1.txt 2.txt 3.txt # 多个文件 479171af5e65e23a97b58c343c4de7411 1.txt 5d68dae595d597fb67c85a8301521b097 2.txt 672d93867588107cf46b2cc7ea400d0aa 3.txt 7$ md5sum --tag 1.txt 2.txt 3.txt # BSD 风格 8MD5 (1.txt) = 79171af5e65e23a97b58c343c4de7411 9MD5 (2.txt) = d68dae595d597fb67c85a8301521b097 10MD5 (3.txt) = 72d93867588107cf46b2cc7ea400d0aa 11

校验 MD5 值

1$ md5sum 1.txt 2.txt 3.txt > md5.txt 2$ md5sum -c md5.txt # 校验 31.txt: OK 42.txt: OK 53.txt: OK 6

#相关命令

命令说明
b2sum计算和校验 BLAKE2 值
sha1sum计算和校验 SHA1 值
sha224sum计算和校验 SHA224 值
sha256sum计算和校验 SHA256 值
sha384sum计算和校验 SHA384 值
sha512sum计算和校验 SHA512 值

#推荐阅读

#手册

显示

1MD5SUM(1) User Commands MD5SUM(1) 2 3NAME 4 md5sum - compute and check MD5 message digest 5 6SYNOPSIS 7 md5sum [OPTION]... [FILE]... 8 9DESCRIPTION 10 Print or check MD5 (128-bit) checksums. 11 12 With no FILE, or when FILE is -, read standard input. 13 14 -b, --binary 15 read in binary mode 16 17 -c, --check 18 read checksums from the FILEs and check them 19 20 --tag create a BSD-style checksum 21 22 -t, --text 23 read in text mode (default) 24 25 -z, --zero 26 end each output line with NUL, not newline, and disable file 27 name escaping 28 29 The following five options are useful only when verifying checksums: 30 --ignore-missing 31 don't fail or report status for missing files 32 33 --quiet 34 don't print OK for each successfully verified file 35 36 --status 37 don't output anything, status code shows success 38 39 --strict 40 exit non-zero for improperly formatted checksum lines 41 42 -w, --warn 43 warn about improperly formatted checksum lines 44 45 --help display this help and exit 46 47 --version 48 output version information and exit 49 50 The sums are computed as described in RFC 1321. When checking, the in‐ 51 put should be a former output of this program. The default mode is to 52 print a line with: checksum, a space, a character indicating input mode 53 ('*' for binary, ' ' for text or where binary is insignificant), and 54 name for each FILE. 55 56 Note: There is no difference between binary mode and text mode on GNU 57 systems. 58 59BUGS 60 Do not use the MD5 algorithm for security related purposes. Instead, 61 use an SHA-2 algorithm, implemented in the programs sha224sum(1), 62 sha256sum(1), sha384sum(1), sha512sum(1), or the BLAKE2 algorithm, im‐ 63 plemented in b2sum(1) 64 65AUTHOR 66 Written by Ulrich Drepper, Scott Miller, and David Madore. 67 68REPORTING BUGS 69 GNU coreutils online help: <https://www.gnu.org/software/coreutils/> 70 Report any translation bugs to <https://translationproject.org/team/> 71 72COPYRIGHT 73 Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU 74 GPL version 3 or later <https://gnu.org/licenses/gpl.html>. 75 This is free software: you are free to change and redistribute it. 76 There is NO WARRANTY, to the extent permitted by law. 77 78SEE ALSO 79 cksum(1) 80 81 Full documentation <https://www.gnu.org/software/coreutils/md5sum> 82 or available locally via: info '(coreutils) md5sum invocation' 83 84GNU coreutils 9.4 April 2024 MD5SUM(1) 85

Bash 的 md5sum 命令》 是转载文章,点击查看原文


上一篇:下一篇:

最近更新


上一篇:下一篇: