After changing the registered thumbnail sizes and regenerating your thumbnails a few times during theme development, you may have quite a few thumbnails left over from old images sizes that don’t match any of the currently registered sizes, but are just sitting there in your uploads directory taking up space. Here is a command which will delete all generated thumbnails, after which you can regenerate your thumbnails one final time and be left with only the sizes currently registered in the theme.
Navigate to your uploads directory, and run this command:
find . -name *-*x*.jpg | xargs rm -f
Note that this will delete ALL generated thumbnails, so only run this if that’s what you want. The originals will be unaffected, unless they are named like a thumbnail.
I was looking all over for a solution to this problem! THANK YOU! 🙂
Thanks. I created a cron job for that.
Thanks! I kept googling two days for a solution to reduce the number of files in my uploads folder (over 58.000 images) and thought I finally found an answer, but when I copy this into Putty it says: “-bash: /bin/find: Argument list too long” 🙁
Thank you!
I had to run separate commands for each thumb size because without specificity, random originals also were deleted for some reason.
find . -name *-*56×56.jpg | xargs rm -f
find . -name *-*125x*.jpg | xargs rm -f
find . -name *-*150x*.jpg | xargs rm -f
find . -name *-*200x*.jpg | xargs rm -f
find . -name *-*250x*.jpg | xargs rm -f
find . -name *-*400x*.jpg | xargs rm -f
find . -name *-*768x*.jpg | xargs rm -f
find . -name *-*940x*.jpg | xargs rm -f
find . -name *-*1024x*.jpg | xargs rm -f
find . -name *-*2000x*.jpg | xargs rm -f
Where should write that code?
I had to add quotes around the expression to make it work. Thanks for the snippet.
#THIS OUTPUTS A LIST OF FILES
find ./ -name “*-*x*.jpg”
#THIS DELETES THE FILES
find ./ -name “*-*x*.jpg” | xargs rm -f
Hi
Using : find . -name *-*x*.jpg | xargs rm -f is very dangerous because it can mach original images! That’s what happened to mo… 🙁
Exemple (french), those originals images were deleted:
home-bordeaux.jpg
parement-mural-texture-portland.jpg
***
Try this to list:
find . -regextype posix-extended -regex ‘.*\-[0-9]{1,5}x[0-9]{1,5}\.jpe?g$’
Then to delete:
find . -regextype posix-extended -regex ‘.*\-[0-9]{1,5}x[0-9]{1,5}\.jpe?g$’ -delete