How to create a md5-file for every folder in a drive recursively?

5,419

Solution 1

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 

Solution 2

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.

Share:
5,419

Related videos on Youtube

tristank
Author by

tristank

Updated on September 18, 2022

Comments

  • tristank
    tristank over 1 year

    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.

    • Admin
      Admin over 11 years
      Why do you need a script if you have md5deep, why not just md5deep -r [folder name]?
    • Admin
      Admin over 11 years
      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.
    • Admin
      Admin over 11 years
      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.
    • Admin
      Admin over 11 years
      So it's not possible?
    • Admin
      Admin over 11 years
      Similair to what integritychecker on mac os x does: diglloydtools.com/integritychecker.html
    • Admin
      Admin over 11 years
      It just seems strange to me - why do you want all those files? - note that in your link it says integritychecker creates one file per directory, not per file. But md5deep is designed to do the verification step with a single file that lists everything, and I don't understand why you don't want that. I guess what I'm asking is - what are you going to do with all those files?
    • Admin
      Admin over 11 years
      Yeah, you are right I got it wrong. I thought this way I could checksum single files rather than to checksum the whole content of the folder.
    • Admin
      Admin over 11 years
      So what do I do if I want md5deep to create single md5-file for every folder in a specific drive?
  • YoloTats.com
    YoloTats.com over 11 years
    @la_tristesse I rewrote my answer. Please be more specific in your questions in the future.