Skip to content

Instantly share code, notes, and snippets.

@derralf
Created February 26, 2026 10:53
Show Gist options
  • Select an option

  • Save derralf/215a5fff5da652bbd130be7474cfc645 to your computer and use it in GitHub Desktop.

Select an option

Save derralf/215a5fff5da652bbd130be7474cfc645 to your computer and use it in GitHub Desktop.
Find and delete Wordpress Thumbnails
#!/bin/bash
################################################################################
#
# WordPress Thumbnail Finder (macOS / BSD find)
#
# Was macht dieses Skript?
#
# Dieses Script:
# - findet WordPress-Thumbnails wie "-150x150.jpg"
# - findet "-scaled.jpg" Dateien
# - erstellt daraus ein Lösch-Script: delete-thumbs.sh
#
#
# Vorteil:
# Es wird nichts direkt gelöscht.
# Stattdessen wird ein Lösch-Script ("delete-thumbs.sh") erzeugt,
# das vor dem Ausführen geprüft werden kann.
#
#
# Nutzung:
# 1. Script in gewünschten Ordner legen
# 2. cd in diesen Ordner
# 3. ./find-thumbs.sh
# 4. delete-thumbs.sh prüfen
# 5. ./delete-thumbs.sh ausführen
#
################################################################################
echo "Erstelle delete-thumbs.sh ..."
echo "#!/bin/bash" > delete-thumbs.sh
echo "" >> delete-thumbs.sh
# -scaled Dateien
find -E . -type f -regex '.*-scaled\.(jpg|jpeg|png|webp)$' \
-print0 | xargs -0 -I {} echo rm "\"{}\"" >> delete-thumbs.sh
# -123x456 Thumbnails
find -E . -type f -regex '.*-[0-9]+x[0-9]+\.(jpg|jpeg|png|webp)$' \
-print0 | xargs -0 -I {} echo rm "\"{}\"" >> delete-thumbs.sh
chmod +x delete-thumbs.sh
echo "Fertig."
echo "Bitte delete-thumbs.sh prüfen und danach ausführen."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment