Skip to content

Instantly share code, notes, and snippets.

@rwohleb
Created September 7, 2013 20:22
Show Gist options
  • Save rwohleb/6478944 to your computer and use it in GitHub Desktop.
Save rwohleb/6478944 to your computer and use it in GitHub Desktop.
#!/bin/bash
DIR="/path/to/big/files"
find $DIR -type f -exec md5sum {} \; | sort > /tmp/sums-sorted.txt
OLDSUM=""
IFS=$'\n'
for i in `cat /tmp/sums-sorted.txt`; do
NEWSUM=`echo "$i" | sed 's/ .*//'`
NEWFILE=`echo "$i" | sed 's/^[^ ]* *//'`
if [ "$OLDSUM" == "$NEWSUM" ]; then
echo ln -f "$OLDFILE" "$NEWFILE"
else
OLDSUM="$NEWSUM"
OLDFILE="$NEWFILE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment