WordPress Tip: Find and delete generated images

When you are changing themes on a site or altering the image sizes used on a WordPress site, you’ll have to regenerate all the image sizes. Maybe you ran into the situation that you want to move the site and will have to generate new images again, after the move. For those that have SSH access to their site or local development environment, here are two simple tips I used for as long as I can remember them 😁.

Find & delete generated images

By default WordPress stores the generated image files in the following format:

// WordPress generated image file names

// Example for a thumbnail image size

The files generated will be stored in the uploads folder, usually within the wp-content folder on your site. On Linux based server or macOS, you usually have access to the find command:

The aforementioned commands will find and delete the generated image sizes for you, but be careful, it’s a very powerful command.

Regenerate WordPress image sizes

The second gist regenerates all the image sizes. Make sure you have the WordPress command line interface installed on your server. Otherwise you can use a plugin like Regenerate Thumbnails.

Find both commands in this Gist.

6 thoughts on “WordPress Tip: Find and delete generated images”

  1. I’d be careful there – it’d delete any file with an x in the middle of the file name! Try this: find -E . -type f -regex “.*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)”


Leave a Comment