3

It seems to me that .md5 checksum files provided for verifying downloads mostly contain the checksum for the file to verify, but not the filename.

Using md5sum that's seemingly a bit impractical, because when -checking it wants md5 key and filename separated by whitespace as input.

So, given these files that just contains the checksum, what is the most practical one-liner for checking them?

  1. This post suggests a way, but warrants manual input of key and file name.

    md5sum -c - <<< "b4460802b5853b7bb257fbf071ee4ae2 foo"
    
  2. This post has this interesting suggestion, but I find it a bit hard to read and type:

    cmp foo.md5 <(md5sum foo | awk '{print $1}') && echo $?
    
  3. This works but is impractical because of the manual input of the filename (that doesn't autocomplete on my system):

    printf $(cat foo.md5)\\tfoo | md5sum -c -
    

    and this autocompletes but feels unwieldy:

    printf "%s %s" $(cat foo.md5) foo | md5sum -c -
    
  4. This is better because autocomplete works, but it's potentially a bit long, and also three steps.

    md5sum foo | awk '{printf $1}' | diff foo.md5
    

Any further ideas?

  • It contains the filename: md5sum /etc/passwd d1924de8258210b319ec74c188e66d45 /etc/passwd – Ipor Sircer Nov 10 '16 at 10:25
  • I mean downloaded checksum files, I'll update the question – lash Nov 10 '16 at 10:26
  • Why not write a simple shell script, and put checking into that? As a bonus you can include a wget command to download the file as well. Shell script golf is fun, but not necessarily practical, if you really need to use this command often. – dirkt Nov 10 '16 at 10:33
1

The problem is that the site you link to doesn't have standard md5 files.
Md5 files there lack the file name for each signature. The signature and file name have to be reconstructed.

How about:

md5sum -c <<<"$b"

Or:

md5sum -c <(echo $(<$a.md5) $a)

where $a and $b are:

a="jackson-annotations-2.8.4.jar"
b="$(<jackson-annotations-2.8.4.jar.md5) jackson-annotations-2.8.4.jar"

Or, simpler:

a=jackson-annotations-2.8.4.jar; b="$(<$a.md5) $a"

All in one line with the file(s) names (two solutions):

a=jackson-annotations-2.8.4.jar; b="$(<$a.md5) $a"; md5sum -c <<<"$b"
a=jackson-annotations-2.8.4.jar; md5sum -c <(echo $(<$a.md5) $a)

The whole script I used was:

#!/bin/bash
a=jackson-annotations-2.8.4.jar
site=https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.8.4

wget -N "$site/$a"
wget -N "$site/$a.md5"

b="$(<$a.md5) $a"

md5sum -c - <<<"$b"
0

This is the best you can get as you are using non standard md5 checksum lines in files. The one liner below does not need copying any values from files, just the filename itself and the file containing the md5 sum

md5sum -c <<< $(echo $(cat jackson-annotations-2.8.4-javadoc.jar.md5) jackson-annotations-2.8.4-javadoc.jar)

  • A bit of explanation on why this solves the problem would be great. – countermode Nov 10 '16 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.