Tag Archives: debian

Free space in your WordPress install by deleting old image sizes

If you change your theme often, your uploads folder will accumulate thumbnails of images in many sizes that you no longer use. This consumes disk space unnecessarily. I wish someone coded a plugin for this, but failing that, a handy way to do this via SSH is:

find . -name *-250x250.* | xargs rm -f

Where 250×250 is the image size you want to delete. You could also try something like:

find . -name *-250x*.* | xargs rm -f

if you have multiple thumbnail sizes like 250×250 250×300 etc.

What I do is list images in the folders to see the unwanted sizes there, and run this delete a few times with various sizes. A more ruthless person could try something like:

find . -name *-*x*.* | xargs rm -f

I do not recommend this, as it can match several files that you may not want to delete, for example a file with a hyphenated name and the letter x in the last hyphenated word, like “wish-merry-xmas.jpg” for example, which wouldn’t be a resized image, but an original or worse, it could be another file and not an image at all, like “here-are-exact-directions-to-our-property.html”.

But if you have a lot of thumbnail sizes, you may feel tempted anyway. Two suggested precautions. Change directory to your uploads folder (you should do this in any case)
cd /path/to/wprdpress/wp-content/uploads
find . -name *-*x*.* | xargs rm -f

The other precaution to take is to specify extension.
find . -name *-*x*.jpg | xargs rm -f
find . -name *-*x*.png | xargs rm -f

This will give you some protection from inadvertently deleting non-resize uploads like “entertaining-extras.pdf”

of course, if you are a patient soul (or don’t have too many files uploaded), you could find the files before deleting to see if any other files are getting selected along with resizes.

find . -name *-*x*.*
and if all is well
find . -name *-*x*.* | xargs rm -f

Do you have a better method?

Enhanced by Zemanta