0

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?

0

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .