I want to dump a sha
checksum (here using sha1sum
, I know it is not to be used for crypto, do not worry this is fine for my need) to disk from a bash script. So far, I am able to get it dumped (without anything extra...). But I do not manage to dump it in binary format, instead I am only getting a plaintext hex dump:
$ echo "bla" | sha1sum | awk '{print $1}' | head -c-1 > test
$ ls -lrth test
-rw-r--r-- 1 jrlab jrlab 40 mars 2 15:02 test
$ xxd test
00000000: 3034 3735 3935 6430 6661 6539 3732 6662 047595d0fae972fb
00000010: 6564 3063 3531 6234 6134 3163 3761 3334 ed0c51b4a41c7a34
00000020: 3965 3063 3437 6262 9e0c47bb
For example here, if I am right, the output of sha1
is truly 20 bytes long, which takes 40 chars to represent in hex printout (i.e. 40 bytes with encoding the hex printout in ASCII, and this is the reason why xxd can transcript all bytes of the file as chars 0-f), and this is what is present on my file. How can I change this so that the size of test
is 20 bytes on disk, i.e. truly dumped in binary format?
Sorry if I missed an easy way to do this, I have been googling (probably the wrong question) for quite some time without finding a clear answer.