Skip to content

Instantly share code, notes, and snippets.

@neverything
Last active March 22, 2023 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neverything/b17bbc75e558e6525756476ae2d0324d to your computer and use it in GitHub Desktop.
Save neverything/b17bbc75e558e6525756476ae2d0324d to your computer and use it in GitHub Desktop.
Sometimes you only want the original images and not the generated sizes <name-of-image>-150x150.png. This command deletes all the files with a certain pattern in the file name. See https://silvanhagen.com/wordpress-delete-generated-images/ for more details.
# List the files
find -E . -type f -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)"
# DANGER! Delete the files
find -E . -type f -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -delete
# If your OS doesn't support -E (tip from https://github.com/quasel)
find . -type f -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)"
# Improved with the help of https://github.com/markhowellsmead
# Regenerate all media files and sizes
wp media regenerate --yes
# empty space for copying
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment