26

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.

gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
Sharon
  • 263
  • 1
  • 3
  • 4

2 Answers2

49
echo -n 'exampleString' | md5sum

should work.

ashiaka
  • 3,994
  • 8
  • 32
  • 45
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
  • 1
    And 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
    Oh, sorry man i edit my answer, ok? Yes, i saw the problem for the hash – Nhoya Mar 14 '15 at 16:20
  • But now, in what is your answer different from the previous accepted answer? – gniourf_gniourf Mar 14 '15 at 16:23
  • 2
    Sharon 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