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

在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.

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值