I have 2 files test.txt and test.txt.md5. I would like to verify the checksum of test.txt.
The gnu tool md5sum requires an md5 file with the following format "[md5-hash][space][space][filename]" (md5sum -c test.txt.md5). Unfortunately my test.txt.md5 only contains the md5 hash (without the spaces and filename).
How can I pass the hash from the "test.txt.md5" file to the "md5sum -c" command? I guess I have to use the standard input however all examples I have seen try to recreate the md5sum file format
The content of the files is:
test.txt
:
test
and test.txt.md5
:
d8e8fca2dc0f896fd7cb4cb0031ba249
Best Answer
Like many commands,
md5sum
has the ability to read from the standard input if an option's value is-
(fromman md5sum
):Since you know the file name, you could simply print the contents of your md5 file, a couple of spaces and then the name and pass that to
md5sum
:Another option would be to add the file name to your file: