Skip to content
 

How to create a md5sum of a partial part of a file

At home I have a NAS that holds all my media files. Next to residing on my NAS these files are also backed up to dvd. To be able to move these files around while also changing their filenames I needed an way to fingerprint these files.

As I only needed the fingerprint to match files to each other, not to validate their contents, and as the files reside on an external disk I though that using md5sum would be too much. So I’ve created a small shell script that creates a fingerprint using only the first megabyte of a file.

The script md5sum_partial:

#!/bin/sh
FILE="$1"
MD5=`head -c 1M "$FILE"  | md5sum | sed -e 's/ -//'`
echo "$MD5 $FILE"

To recursively run it on an entire directory and send the output the STDOUT run

find . -type f -print0 |xargs -0 -IF md5sum_partial F

Leave a Reply