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

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

码农世界 2024-05-27 前端 74 次浏览 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使用示例》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,74人围观)参与讨论

还没有评论,来说两句吧...

Top