Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Last active November 23, 2017 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lewiscowles1986/b91d4e4c9d6322823300292e73186e88 to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/b91d4e4c9d6322823300292e73186e88 to your computer and use it in GitHub Desktop.
De-duplicate JPG Files
#!/bin/bash
PATH_TO_PROCESS="./"
if [ $# -ge 1 ]; then
PATH_TO_PROCESS=${1}
fi
JPEG_QUALITY=80
if [ $# -ge 2 ]; then
JPEG_QUALITY=${2}
fi
IMPROVEMENT_THRESHOLD=1
if [ $# -ge 3 ]; then
IMPROVEMENT_THRESHOLD=${3}
fi
find $PATH_TO_PROCESS -type f -iname '*.jpg' -exec jpegoptim -p -P --max=$JPEG_QUALITY --threshold=$IMPROVEMENT_THRESHOLD --strip-all {} +
fdupes -rn1 $PATH_TO_PROCESS | sed -e 's/\(\w\) /\1|/g' -e 's/|$//' > files
while read line; do
IFS='|' read -a arr <<< "$line"
orig=${arr[0]}
for ((i = 1; i < ${#arr[@]}; i++)); do
file="${arr[$i]}"
ln -sf "$orig" "$file"
done
done < files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment