Last active
November 23, 2017 07:06
-
-
Save Lewiscowles1986/b91d4e4c9d6322823300292e73186e88 to your computer and use it in GitHub Desktop.
De-duplicate JPG Files
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 | |
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