Score:0

Cleaning up WordPress thumbnails; trying to find all thumbnails and delete them on Ubuntu 22

it flag

So, I'm trying to clean up some backups I have, and they're getting bigger and bigger because of, mainly, the number of thumbnails generated by WordPress per image. I came close to finding a solution, but, naturally, there are a few outliers that make my solution not work, and I can't figure out either the proper regular expression or an alternative way to handle this.

Currently, I am going this route:

First, find all the images: find . -regex '.*[a-z]-[0-9]+x[0-9]+\.(png|jpg|webp)' | xargs ls

Then, I'd delete them like so: find . -regex '.*[a-z]-[0-9]+x[0-9]+\.(png|jpg|webp)' | xargs rm -f

This would work fine for thumbnails such as seo-magnifier-256x256.png.

However, the outliers are favicons such as images as favicon-16x16.png, apple-touch-icon-114x114.png, mstile-150x150.png, and android-chrome-512x512.png (there are more with different dimensions).

So, I was trying to figure out the regex to exclude images that started with (favicon|apple-touch-icon|mstile|android-chrome) but I can't seem to get it.

Would anyone be able to help me out in determining the proper regex or a better way to handle this scenario?

Score:1
cn flag

What I would do:

$ ls -1
apple-touch-icon-magnifier-256x256.png
favicon-magnifier-256x256.png
seo-magnifier-256x256.png
$ find . -regextype egrep \
    -not -regex '.*/(favicon|apple-touch-icon|mstile|android-chrome).*' \
    -regex '.*[a-z]-[0-9]+x[0-9]+\.(png|jpg|webp)' \
./seo-magnifier-256x256.png

Finally, to delete if you are happy with the result, append -delete to the end of find's command.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.