Deleting WordPress Postfix Image Files: A Step-by-Step Guide

If you manage a WordPress site, you’ve likely noticed that it generates multiple image sizes for uploaded files, appending postfixes like -300×300.jpg to filenames. These files can take up unnecessary space, especially if they’re not in use. This guide will show you how to delete these files while keeping the original images intact, using the find command in Linux.

What Are Postfix Files?

WordPress automatically creates resized versions of uploaded images, appending postfixes that indicate dimensions, such as -WidthxHeight. Examples:

  • image-300×300.jpg
  • photo-150×150.webp

The original files remain unaltered:

  • image.jpg
  • photo.webp

Objective

The goal is to delete all postfix image files (e.g., -300×300.jpg) while preserving the original versions.

⚠️ Important: Backup First!

Solution Using find

One-Liner Command

Replacing /path/to/your/directory with the path to your WordPress image directory:

find /path/to/your/directory -type f \( \
  -name "*-[0-9]*x[0-9]*.jpg" \
  -or -iname "*-[0-9]*x[0-9]*.jpeg" \
  -or -iname "*-[0-9]*x[0-9]*.png" \
  -or -iname "*-[0-9]*x[0-9]*.gif" \
  -or -iname "*-[0-9]*x[0-9]*.webp" \
\) -delete

Verify Before Deletion

To check which files will be deleted without actually removing them, replace -delete with -print:

find /path/to/your/directory -type f \( \
  -name "*-[0-9]*x[0-9]*.jpg" \
  -or -iname "*-[0-9]*x[0-9]*.jpeg" \
  -or -iname "*-[0-9]*x[0-9]*.png" \
  -or -iname "*-[0-9]*x[0-9]*.gif" \
  -or -iname "*-[0-9]*x[0-9]*.webp" \
\) -print

Conclusion

This simple script and approach help keep your WordPress directories clean by removing unnecessary image files generated by the system. Just remember to always back up your data before running deletion commands.