so I'm trying to work out how to hash all files within a USB directory. I came across another post similar to mine including this script below:
find "$PWD" -type d | sort | while read dir; do [ ! -f "${dir}"/@md5Sum.md5 ] && echo "Processing " "${dir}" || echo "Skipped " "${dir}" " @md5Sum.md5 already present" ; [ ! -f "${dir}"/@md5Sum.md5 ] && md5sum "${dir}"/* > "${dir}"/@md5Sum.md5 ; chmod a=r "${dir}"/@md5Sum.md5;done
It works really well and does everything I'd want it to do however I can't figure out how to alter it to target the USB. I've already got the user to input the USB device by them inputting /dev/sdf or /dev/sdg etc. But I can't figure out how to carry this information into the command above. Any advice or suggestions on this would be appreciated.
cd
to the mountpoint and run your script. – sudodus Dec 29 '21 at 10:12lsblk -f
andlsblk -m
to get a list of all drives and partitions and that way identify the USB drive's device letter. You can clone it with a crude method usingdd
to another drive or to an image file, or more efficiently with Clonezilla. It is difficult to get a reproducible md5sum of the cloned drive because the target drive might be bigger than the original one. Instead test that the cloned copy works correctly. – sudodus Dec 29 '21 at 10:35dd
using bs and count and pipe the result tomd5sum
. After cloning you should check that you get the same result on the target drive. Please notice that drives are usually not exactly the same size (in bytes), so it is important to check with the same numbers for bs and count. (The target drive must be big enough to copy until the end of the last partition of the source drive.) – sudodus Dec 29 '21 at 11:06find "/dev/$source" -type d | sort | while read source; do [ ! -f "${source}"/@md5Sum.md5 ] && echo "Processing " "${source}" || echo "Skipped " "${source}" " @md5Sum.md5 already present" ; [ ! -f "${source}"/@md5Sum.md5 ] && md5sum "${source}"/* > "${dir}"/@md5Sum.md5 ; chmod a=r "${source}"/@md5Sum.md5;done
After doing this, no progress is appeared to made and nothing is created in said USB... Soooo im a little bit stumped now
– cameron.g Dec 29 '21 at 12:04