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.
Asked
Active
Viewed 2.4k times
26

gniourf_gniourf
- 44,650
- 9
- 93
- 104

Sharon
- 263
- 1
- 3
- 4
-
@Flimzy: That would try to run `md5sum` on a file at that location, not on the string itself. – Oliver Charlesworth Aug 28 '11 at 17:55
2 Answers
49
echo -n 'exampleString' | md5sum
should work.

ashiaka
- 3,994
- 8
- 32
- 45
-
-
The only issue is that CRLF and LF line break types will output different hashsum, so have to be careful about the environment and the terminal used. – Shayan Jul 11 '22 at 14:18
19
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)

Nhoya
- 413
- 1
- 5
- 11
-
@ gniourf_gniourf stay easy, i gived the answer to him, with and without my code.. btw ./gensum -t gniourf_gniourf md5: d41d8cd98f00b204e9800998ecf8427e - sha1: adc83b19e793491b1c6ea0fd8b46cd9f32e592fc - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - it works. – Nhoya Mar 14 '15 at 16:13
-
1And by the way, [these are not the correct hash sums of `gniourf_gniourf`](http://www.fileformat.info/tool/hash.htm?text=gniourf_gniourf). – gniourf_gniourf Mar 14 '15 at 16:19
-
1
-
But now, in what is your answer different from the previous accepted answer? – gniourf_gniourf Mar 14 '15 at 16:23
-
2Sharon asked for sha1, sha256 and md5, i gived all the 3 and btw i didn't see the epoch, sorry again oh and problem solved in the script :P – Nhoya Mar 14 '15 at 16:25