Linux 字符串校验和

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7222746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:55:14  来源:igfitidea点击:

Checksum on string

linuxbashchecksum

提问by Sharon

Is there a way to calculate a checksum on a string in Linux? The checksum commands that I have seen (cksum, md5sum, sha1sum, etc.) all require a file as input and I do not have a file. I only have a path to a location and want to calculate the checksum on that path.

有没有办法在 Linux 中计算字符串的校验和?我见过的校验和命令(cksummd5sumsha1sum等)都需要一个文件作为输入,而我没有文件。我只有一个位置的路径,并且想计算该路径上的校验和。

采纳答案by ashiaka

echo -n 'exampleString' | md5sum

should work.

应该管用。

回答by Nhoya

echo -n "yourstring" |md5sum
echo -n "yourstring" |sha1sum
echo -n "yourstring" |sha256sum

don't forget -n or the result will change (cuz the newline will be parsed)

不要忘记 -n 否则结果会改变(因为将解析换行符)