国际访客建议访问 Primers 编程伙伴 国际版站点 > Bash 教程 > b2sum 以获得更好的体验。

# Bash 的 b2sum 命令

b2sum [OPTION]... [FILE]...

!subtitle:功能

计算或校验 BLAKE2 值。

!subtitle:类型

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

!subtitle:参数

  • OPTION 选项:

    • -b, --binary - 以二进制模式读取文件;类 UNIX 系统下始终是二进制模式

    • -c, --check - 从文件中读取 BLAKE2 值进行校验

    • -l, --length=BITS - 结果保留的长度(位),不能超过 512 且必须是 8 的倍数

    • --tag- 生成 BSD 风格的输出

    • -t, --text - 以文本模式读取文件;类 UNIX 系统下不存在文本模式,此选项无效

    • -z, --zero - 以空字符(\0)作为行的结尾,而不是换行符(\n

    • --ignore-missing - 校验时忽略缺失的文件

    • --quiet - 校验时不打印成功的消息

    • --status - 校验时不打印任何消息;可以通过返回值检查是否成功

    • --strict - 校验时严格检查格式

    • -w, --warn - 校验时遇到格式不正确的行时产生警告

    • --help - 显示帮助

    • --version - 显示版本

  • FILE - 文件列表

# 示例

!subtitle:计算 BLAKE2 值

$ b2sum 1.txt                                       # 单个文件
364dce569668afdf7620e6a0a118c7ef718f4df1b419333cd41373d1af91ccc4f619b1a245c543e715bc6c3d95871c0936f94b7875687bd09154e4af70cfd987  1.txt
$ b2sum -l 64 1.txt                                 # 结果保留 64 位
31e4af026ab94028  1.txt
$ b2sum 1.txt 2.txt 3.txt                           # 多个文件
364dce569668afdf7620e6a0a118c7ef718f4df1b419333cd41373d1af91ccc4f619b1a245c543e715bc6c3d95871c0936f94b7875687bd09154e4af70cfd987  1.txt
cdf8234a9831d36804b2ccf54288127cbe6c876a9167d9f863334c9714ccfa8d73e9b644819e2ec37b17de1c5d7381d5c7d1806f6bd021dcfda5def7e958e336  2.txt
b9fd7b32f6e9ecaa4f48b1bb22a160fe716c67835e8d2e67f0a3fb2f3b6cdd266499d2e1926dfae79c436202e8136ff930e8bf384899dd7be7ae4ee7b12afa4e  3.txt
$ b2sum --tag 1.txt 2.txt 3.txt                     # BSD 风格
BLAKE2b (1.txt) = 364dce569668afdf7620e6a0a118c7ef718f4df1b419333cd41373d1af91ccc4f619b1a245c543e715bc6c3d95871c0936f94b7875687bd09154e4af70cfd987
BLAKE2b (2.txt) = cdf8234a9831d36804b2ccf54288127cbe6c876a9167d9f863334c9714ccfa8d73e9b644819e2ec37b17de1c5d7381d5c7d1806f6bd021dcfda5def7e958e336
BLAKE2b (3.txt) = b9fd7b32f6e9ecaa4f48b1bb22a160fe716c67835e8d2e67f0a3fb2f3b6cdd266499d2e1926dfae79c436202e8136ff930e8bf384899dd7be7ae4ee7b12afa4e

!subtitle:校验 BLAKE2 值

$ b2sum 1.txt 2.txt 3.txt > sum.txt
$ b2sum -c sum.txt # 校验
1.txt: OK
2.txt: OK
3.txt: OK

# 推荐阅读

# 手册

B2SUM(1)                         User Commands                        B2SUM(1)

NAME
       b2sum - compute and check BLAKE2 message digest

SYNOPSIS
       b2sum [OPTION]... [FILE]...

DESCRIPTION
       Print or check BLAKE2b (512-bit) checksums.

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

       Mandatory  arguments  to  long  options are mandatory for short options
       too.

       -b, --binary
              read in binary mode

       -c, --check
              read checksums from the FILEs and check them

       -l, --length=BITS
              digest length in bits; must not exceed the max  for  the  blake2
              algorithm and must be a multiple of 8

       --tag  create a BSD-style checksum

       -t, --text
              read in text mode (default)

       -z, --zero
              end  each  output  line  with NUL, not newline, and disable file
              name escaping

   The following five options are useful only when verifying checksums:
       --ignore-missing
              don't fail or report status for missing files

       --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 7693.  When checking, the in‐
       put should be a former output of this program.  The default mode is  to
       print a line with: checksum, a space, a character indicating input mode
       ('*'  for  binary,  ' ' for text or where binary is insignificant), and
       name for each FILE.

       Note: There is no difference between binary mode and text mode  on  GNU
       systems.

AUTHOR
       Written by Padraig Brady and Samuel Neves.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2023  Free Software Foundation, Inc.  License GPLv3+: GNU
       GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free  to  change  and  redistribute  it.
       There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       cksum(1)

       Full documentation <https://www.gnu.org/software/coreutils/b2sum>
       or available locally via: info '(coreutils) b2sum invocation'

GNU coreutils 9.4                 April 2024                          B2SUM(1)
本文 更新于: 2025-11-27 09:38:13 创建于: 2025-11-27 09:38:13