Last active
August 29, 2015 14:01
-
-
Save bradley219/4ca51307cabbb5919585 to your computer and use it in GitHub Desktop.
Find duplicate files for a given path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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