当前位置: 首页> 游戏> 手游 > macos 计算字符串/文件md5, 计算文件hash命令shasum使用示例

macos 计算字符串/文件md5, 计算文件hash命令shasum使用示例

时间:2025/7/10 14:11:00来源:https://blog.csdn.net/tekin_cn/article/details/139229828 浏览次数:0次

在mac系统中,自带的有命令md5 可以帮我们计算文件或者字符串的md5值, shasum命令可以帮我们计算文件sha值。 其使用方法如下:

md5 命令

语法: md5 [-pqrtx] [-s string] [file ...]

ps:  在unix类系统的命令语法中,中括号[] 中的表示可选项,这个是默认的公用规范,必须要学会!!

计算字符串md5

➜  ~ md5 -s admin
MD5 ("admin") = 21232f297a57a5a743894a0e4a801fc3

计算文件md5

➜  ~ md5 yourfile.txt
MD5 (yourfile.txt) = 7b4b08855739c05400155d5a3445be78

md5命令选项
-s string
             Print a checksum of the given string.

 -p      Echo stdin to stdout and append the checksum to stdout.

 -q      Quiet mode - only the checksum is printed out.  Overrides the -r
         option.

 -r      Reverses the format of the output.  This helps with visual diffs.
         Does nothing when combined with the -ptx options.

 -t      Run a built-in time trial.

 -x      Run a built-in test script.
 

shasum命令

计算文件hash 支持的sha算法有 224, 256, 384, 512, 512224, 512256

➜  ~ shasum -a 256 yourfile.txt
028fc9f1c34dc30358d650ab61c757f1e087545690642e24ede8d947a146af4c  yourfile.txt

使用默认算法 sha224来计算文件sha

➜  ~ shasum  yourfile.txt
1b2ed9e3929e0461108cf2c224485ba75135844b  yourfile.txt


命令选项:
  -a, --algorithm   1 (default), 224, 256, 384, 512, 512224, 512256
  -b, --binary      read in binary mode
  -c, --check       read SHA sums from the FILEs and check them
      --tag         create a BSD-style checksum
  -t, --text        read in text mode (default)
  -U, --UNIVERSAL   read in Universal Newlines mode
                        produces same digest on Windows/Unix/Mac
  -0, --01          read in BITS mode
                        ASCII '0' interpreted as 0-bit,
                        ASCII '1' interpreted as 1-bit,
                        all other characters ignored
The following five options are useful only when verifying checksums:
      --ignore-missing  don't fail or report status for missing files
  -q, --quiet           don't print OK for each successfully verified file
  -s, --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

  -h, --help        display this help and exit
  -v, --version     output version information and exit

When verifying SHA-512/224 or SHA-512/256 checksums, indicate the
algorithm explicitly using the -a option, e.g.

  shasum -a 512224 -c checksumfile

The sums are computed as described in FIPS PUB 180-4.  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 type
(`*' for binary, ` ' for text, `U' for UNIVERSAL, `^' for BITS),
and name for each FILE.  The line starts with a `\' character if the
FILE name contains either newlines or backslashes, which are then
replaced by the two-character sequences `\n' and `\\' respectively.

关键字:macos 计算字符串/文件md5, 计算文件hash命令shasum使用示例

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: