Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have files like this.

md1.gz
md1.gz.md5
md2.gz
md2.gz.md5
....
md300.gz
md300.gz.md

Is there any application (or command line) to check the md5 of all files ?

EDIT: Currently I use cfv from macport. work great without any modification

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

The md5 command will check multiple files for you. Simply list all the files you want after the command. I.e. md5 md1.gz md2.gz md3.gz. It will output the md5 hashes like so:

MD5 (md1.gz) = 1c2c02b085a1bc2fed683eca86c0df02
MD5 (md1.gz) = c5515451d8f90a822457a4a8e4bf1791

If you want just the hashes, use the -q flag, it will print only the hash, without the identifying information.

I'm guessing that you want to compare the hash of the files against that in the corresponding .md5 file. You could write a quick shell script to check each generated hash against the one stored in the .md5 file.

Something like this should work:

#!/bin/bash

for file in "$@";
do
  generatedhash=`md5 -q "$file"`
  storedhash=`cat "$file".md5`
  if [ $generatedhash != $storedhash ] ; then
    echo "Hash for file" "$file" "does not match"
  fi
done

Save that to a text file, call it something like checkmd5.sh and do chmod +x checkmd5.sh in the terminal.

It will print out a warning for all files that don't have a matching hash. It prints nothing if the hashes do match. It's quick and dirty, so apologies if it doesn't work for your particular case. But based on the examples you gave, if you run ./checkmd5.sh md*.gz it should check the hashes of the .gz files against the corresponding .md5 files and tell you if any are bad.

share|improve this answer
    
I remember using "something" in linux box to do a hash check with multiple file but I can't remember so I wonder if osx have the same thing. –  Tg0 Nov 7 '11 at 21:35
    
Glad it's what you're looking for. I added a sample script that should work for you. –  robmathers Nov 7 '11 at 21:42
add comment

If want to use a gui, you can try with ff_md5drop

share|improve this answer
add comment

md5deep is a great cross platform tool to generate and check md5/sha hashes. While it's easy to replicate the recursive hash generation feature in a few lines of shell code, it's not so easy to do that for its hash matching feature.

http://md5deep.sourceforge.net/start-md5deep.html#install

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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