My default media setting in WordPress blog is 150x150, 300x300, 1024x1024 respectively for thumbnail, medium, large images. Now I am designing a theme that need different size thumbnail images to show in theme. For this, I go to the media setting again and changed the setting with my news sizes like 72x72, 250x250, 400x400 respectively for thumbnail, medium, large images.

But now to resize my old uploaded images, I used Regenerate Thumbnails WordPress plugin and that generated my new media setting images size easily. So this solved my main problem.

Main Question:

Now the main problem that just occurred is that my hosting space is now going to end. When I checked my files then found that I have 7 images of one image and from that I am only using 4.

first-image-name.jpg
first-image-name-72x72.jpg
first-image-name-150x150.jpg
first-image-name-250x250.jpg
first-image-name-300x300.jpg
first-image-name-400x400.jpg
first-image-name-1024x1024.jpg
second-image-name.jpg
second-image-name-72x72.jpg
second-image-name-150x150.jpg
second-image-name-250x250.jpg
second-image-name-300x300.jpg
second-image-name-400x400.jpg
second-image-name-1024x1024.jpg
...............................
---------- and so on ----------

Now I want to delete 150x150, 300x300, 1024x1024 sizes images. For this many recommend me DNUI (Delete not used images) and Clean Up Images WordPress plugins but they are not picking those old image sizes.

Q:) So How To Delete My Desired Image Sizes From wp-content/uploads folder?

up vote 8 down vote accepted

A quick and easy fix for this is to make use of a plugin called Force Regenerate Thumbnails (to which I don't have any affiliation to)

Unlike a plugin like Regenerating Thumbnails, Force Regenerate Thumbnails creates all your new custom sizes and delete all redundant/orphaned sizes.

Force Regenerate Thumbnails allows you to delete all old images size and REALLY regenerate the thumbnails for your image attachments.

  • Glad it helped. I use this plugin a lot when experimenting with image sizes. :-) – Pieter Goosen Oct 23 '14 at 16:09
  • What version of Wordpress are you running? I'm on 4.0.1 and it throws a ton of errors. – bikey77 Jan 25 '15 at 8:09
  • I haven't tested it on 4.0+. You should contact the plugin author if there is abug in the plugin so that he/she can get to work on that. :-) – Pieter Goosen Jan 25 '15 at 8:46

That's easy! If you have SSH access, log in and do the following for each size. I am just showing 150x150 size only.

Go to the desired uploads folder via command line.

cd /your-site.com/wp-content/uploads

Let's find if that size is available.

find ./uploads/*  -iname '*-150x150.*' -ls

If you see some images as the output then delete 'em with

find ./uploads/*  -iname '*-150x150.*' -exec rm {} \;

Do make sure you back up everything before running such a command.

Or you can search for all the resized images with this command

find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f

If there are any. Then you can delete them all with the following command

find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f -exec rm {}  \;

Again, make sure you back up everything before running such a command.

After all that, instead of generating all sizes again, you can use OTF Regenerate Thumbnails.

This plugin behaves similarly to Regenerate Thumbnails except that images are resized automatically / on the fly, when they are used. Once created, they won't be processed again.

Cheers!

I found another solution using command line

shopt -s globstar 
rm  -- **/*{70x70.png,90x90.png,120x79.png,120x80.png,120x120.png,120x101.jpg,150x150.png,200x180.png,300x199.png,300x251.png}
rm  -- **/*{70x70.jpg,90x90.jpg,120x79.jpg,120x80.jpg,120x120.jpg,120x101.jpg,150x150.jpg,200x180.jpg,300x199.jpg,300x251.jpg}

where 300x251.jpg is your thumbnail file size .

if you want go extreemly do this rm -- **/*{*x*.png,*x*.jpg,*x*.jpeg,*x*.gif} this patter will delete all image have x at end of file name which I do not recommend .

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.