Last active
February 2, 2021 00:00
-
-
Save brunomarks7/1f46799dcd9fb76b0824b4e63d4d416e to your computer and use it in GitHub Desktop.
Cleanup unused wordpress uploads recursively by suffix (filename), like "150x150"
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 | |
# 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 |
Author
brunomarks7
commented
Feb 1, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment