简体   繁体   中英

md5sum validation for a file

I have two files hello.txt and hello.txt.md5

MD5 output is in the below format

cat hello.txt.md5 
b1946ac92492d2347c6235b4d2611184

I wrote a simple script to validate md5sum.

csum=$(cat hello.txt.md5)
echo "$csum hello.txt" | md5sum -c

This script works fine with Ubuntu 13.10 but it throws below error in Ubuntu 12.04 .

md5sum: standard input: no properly formatted MD5 checksum lines found

Can anyone show me how to do this in Ubuntu12.04.

At least on my md5sum files generated have two spaces between checksum and file name. Tested your script and it didn't work, added space between $csum and hello.txt and it did.

The cause is likely to be some change between the md5sum versions.

Doing md5sum <file1> <file2> with both versions should give you an example of what format each version expects.

Specifically, the md5sum man page says:

The default mode is to print a line with checksum, a character indicating type ('*' for binary, ' ' for text), and name for each FILE.

So, for checking in text mode, two spaces shall normally be present (indeed, checking with md5sum -t t.txt confirms this). I guess the new version has lifted this requirement.

Indeed, here's a GNU coreutils commit titled "md5sum: handle BSD reversed format checksums" , dated 2011-09-16. It makes md5sum guess between the two formats.
The commit was released in coreutils 8.14 while Ubuntu 12.04 uses 8.13 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM