Using --check on a md5sum command generated checksum file is failing

1.4k views Asked by At

I'm encountering an error when I try and run md5sum -c on a checksum file I generated. I should mention that I'm running this from PowerShell (as a script will be running this eventually) and this is the cygwin version of md5sum.

I have a test file, jira_defect.txt and I've created a checksum like this:

md5sum jira_defect.txt > result.md5

This gives a file with the following:

7d559b59459052f274e290b5e01a5485 *jira_defect.txt

But when I run

md5sum -c result.md5

I get the infamous error message

result.md5: no properly formatted MD5 checksum lines found

I've tried this again with the -t option, which removes the asterisk, but this hasn't made a difference.

1

There are 1 answers

0
Ansgar Wiechers On BEST ANSWER

Using the redirection operator to write the checksums to an output file causes the file to be created with the default encoding (Unicode). md5sum expects an ASCII file. Use Set-Content (or Out-File) to save the file with ASCII encoding:

md5sum jira_defect.txt | Set-Content result.md5 -Encoding ASCII

You can also work with Unicode files if you pipe their content into md5sum:

Get-Content result.md5 | md5sum -c

Demonstration:

PS C:\> md5sum .\test.ps1 > result.md5
PS C:\> md5sum -c .\result.md5
C:\md5sum.exe: .\result.md5: no properly formatted MD5 checksum lines found
PS C:\> Get-Content .\result.md5 | md5sum -c
.\test.ps1: OK
PS C:\> md5sum .\test.ps1 | Set-Content result.md5 -Encoding ASCII
PS C:\> md5sum -c .\result.md5
.\test.ps1: OK