Skip to content

Instantly share code, notes, and snippets.

@rentalcustard
Created November 29, 2011 09:25
Show Gist options
  • Save rentalcustard/1404148 to your computer and use it in GitHub Desktop.
Save rentalcustard/1404148 to your computer and use it in GitHub Desktop.
file deduping
#!/bin/zsh
typeset -A files_by_sum
find $1 -maxdepth 1 | while read file; do
if [ -f $file ]; then #don't look at directories
sum=$(cat $file | md5sum | awk '{print $1}')
current=${files_by_sum[$sum]}
if [ $current ]; then
rm $file
ln -s $(basename $current) $file
fi
files_by_sum[$sum]=$file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment