Skip to content

Instantly share code, notes, and snippets.

@trajche
Created June 9, 2024 07:26
Show Gist options
  • Save trajche/42c40f4cf147e40573f0a1bbf6aa254c to your computer and use it in GitHub Desktop.
Save trajche/42c40f4cf147e40573f0a1bbf6aa254c to your computer and use it in GitHub Desktop.
find thumbnails in recursing directories and delete them (ex: image-123x456.jpg or file-789x101.png)
directory="./uploads" # Replace with your target directory
# Find top-level directories under /uploads/
find "$directory" -mindepth 1 -maxdepth 1 -type d | while read -r topdir
do
# Find second-level directories inside top-level directories
find "$topdir" -mindepth 1 -maxdepth 1 -type d | while read -r seconddir
do
# Find files with dash (-), number, (x), and number in their filenames
# find "$seconddir" -type f -regex '.*/[^/]*-[0-9]+x[0-9]+[^/]*$' -print
find "$seconddir" -type f -regex '.*/[^/]*-[0-9]+x[0-9]+[^/]*$' -print | while read -r file
do
echo "$file" >> "deletedff.log"
# Remove each file
rm "$file"
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment