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.
Related videos on Youtube
Author by
tristank
Updated on September 18, 2022Comments
-
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 over 11 yearsWhy do you need a script if you have md5deep, why not just
md5deep -r [folder name]
? -
Admin over 11 yearsBecause 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 over 11 yearsThat'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 over 11 yearsSo it's not possible?
-
Admin over 11 yearsSimilair to what integritychecker on mac os x does: diglloydtools.com/integritychecker.html
-
Admin over 11 yearsIt 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 over 11 yearsYeah, 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 over 11 yearsSo what do I do if I want md5deep to create single md5-file for every folder in a specific drive?
-
-
YoloTats.com over 11 years@la_tristesse I rewrote my answer. Please be more specific in your questions in the future.