Skip to content

Instantly share code, notes, and snippets.

@brunomarks7
Last active February 2, 2021 00:00
Show Gist options
  • Save brunomarks7/1f46799dcd9fb76b0824b4e63d4d416e to your computer and use it in GitHub Desktop.
Save brunomarks7/1f46799dcd9fb76b0824b4e63d4d416e to your computer and use it in GitHub Desktop.
Cleanup unused wordpress uploads recursively by suffix (filename), like "150x150"
#!/bin/bash
# Usage
# 1 - Create a folder into any folder (like uploads, or year, or month) and put this script in there.
# 2 - Run "bash cleanup-unused-wordpress-uploads.sh"
currentPath=$(pwd)
echo "Input the crop size pattern"
echo ">> Sample: '150x150' "
read sizePattern
if [ -z $sizePattern ]
then
echo "You need to input the crop size!"
else
echo "Awesome! We're looking at the uploads and creating log file"
find ../ -name "*.jpg" | grep $sizePattern > $sizePattern.txt
echo " "
echo "Do you want to cleanup the images with pattern informed? You can see the log txt file before. [y/N] (Default: N) "
read cleanUpNow
echo $cleanUpNow
if [ "$cleanUpNow" == "y" ];
then
while IFS= read -r line
do
echo "Removing image: $line"
rm "$line"
done < "$sizePattern.txt"
fi
fi
@brunomarks7
Copy link
Author

screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment