3

I'm searching for a script which creates a md5 chechsum file for every single folder inside drive recursivley?

I do have a copy of md5deep on my machine but I'm not that good in scripting bash.

  • 3
    Why do you need a script if you have md5deep, why not just md5deep -r [folder name]? – Random832 Aug 30 '12 at 13:24
  • 1
    Because md5deep creates one file with all checksums. What I want is a md5-file for every single file. For Example: document1.doc document1.md5, document2.doc document2.md5 and so on. – tristank Aug 30 '12 at 13:37
  • That's an unusual thing to want - most people go with either one file with all checksums, or one file per directory with all the files in that directory. – Random832 Aug 30 '12 at 13:38
  • So it's not possible? – tristank Aug 30 '12 at 13:40
  • Similair to what integritychecker on mac os x does: diglloydtools.com/integritychecker.html – tristank Aug 30 '12 at 13:42
5

To get a .md5 file for any files under a specific directory, you can use the following script:

#!/bin/bash
if [ $# -ne 1 ] ; then
        echo "Usage $0 [directory]" 
        exit 1
fi
find $1 -type f  -print0 | while IFS= read -r -d $'\0' file; do
    (
    cd "$(dirname "$file")"
    filename="$(basename "$file")"
    md5sum "$filename" > "$filename".md5
    )
done

In zsh, the same for all files under the current directory can be done with the one-line command (includes files starting with a dot):

for i in **/*(/D) ; do ( cd $i ; for j in *(.D) ; do md5sum $j > $j.md5 ; done ) ; done 
  • @la_tristesse I rewrote my answer. Please be more specific in your questions in the future. – jofel Aug 30 '12 at 14:03
1

Necromancy sure, but I know how we love 1 line-ers

#find / -type f  -exec md5sum {} + > CheckSums

personally I would use sha512sum, and limit to /home or something but if you want to checksum root then go for it.

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.