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.

8
  • 3
    Why do you need a script if you have md5deep, why not just md5deep -r [folder name]?
    – Random832
    Commented Aug 30, 2012 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
    Commented Aug 30, 2012 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
    Commented Aug 30, 2012 at 13:38
  • So it's not possible?
    – tristank
    Commented Aug 30, 2012 at 13:40
  • Similair to what integritychecker on mac os x does: diglloydtools.com/integritychecker.html
    – tristank
    Commented Aug 30, 2012 at 13:42

2 Answers 2

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 
1
  • @la_tristesse I rewrote my answer. Please be more specific in your questions in the future.
    – jofel
    Commented Aug 30, 2012 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .