Skip to content

Instantly share code, notes, and snippets.

@bradley219
Last active August 29, 2015 14:01
Show Gist options
  • Save bradley219/4ca51307cabbb5919585 to your computer and use it in GitHub Desktop.
Save bradley219/4ca51307cabbb5919585 to your computer and use it in GitHub Desktop.
Find duplicate files for a given path
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0 path"
exit 1
fi
TEMPFILE="/tmp/fdupes_`cat /dev/urandom | head -c 1024 | cksum | awk '{print $1}'`"
find "$1" -type f -exec cksum '{}' ';' | sort > "$TEMPFILE"
cat "$TEMPFILE" | awk '{print $1 " " $2}' | uniq -d | while read LINE; do
CHECKSUM=${LINE% *}
SIZE=${LINE##* }
echo "----- CKSUM=$CHECKSUM SIZE=$SIZE -----"
grep "$CHECKSUM" "$TEMPFILE" | awk '{$1=$2=""; print $0}' | cut -b 3-
echo ""
done
rm "$TEMPFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment