Use Plugin for Batch Deletion
WordPress has a rich plugin ecosystem, but there aren't many plugins specifically for batch deleting thumbnails. Naibabiji tested all the ones available on the market, and only the following 3 remained.DNUI
DNUIThis plugin is the most frequently mentioned one in online search resultsfor batch deleting WordPress thumbnails. However, in actual testing,Naibabijiit was found that DNUI's user experience is not good. It can only scan images from the most recent month. On the test site, there were thumbnails from 2017 and 2018 that DNUI could not scan. But the files it did scan can be deleted in batches.Download LinkImage Cleanup
Image CleanupAlthough this WP plugin showed an error alert at the top during testing, it did not affect its functionality. Image Cleanup wasthe only plugin that could completely scan all thumbnail imagesduring Naibabiji's testing for batch deleting WP thumbnails. If you want to use a plugin for deletion, this is a good choice.Download LinkMedia Cleaner
Media Cleaner is the newest plugin among those tested, so its compatibility with WordPress is not an issue. However, testing revealed that this plugin could not scan images from previous folders.Download LinkForce Regenerate Thumbnails
This plugin forces the regeneration of thumbnails, allowing you to delete all old image sizes and truly regenerate thumbnails for image attachments.Download Link Special Note:Regarding the plugins above being unable to scan previous image files, the speculated reason is likely because the previous images on Naibabiji's test site were not written to the database (the database was reset after the site was built). Therefore, the plugins only scanned files that had records in the database and were not referenced by posts.
Manual Batch Deletion
Manual batch deletion is a more reliable method, divided into FTP deletion and SSH command batch deletion. The software needed for this method:#WebsiteBuilding# Free VPS management software Xshell6/Xftp6 Chinese versionDelete using FTP software
Use FTP software (e.g., Xftp) to connect to the server, navigate to your image folder, batch select images with filenames ending in „-numberxnumber“, then right-click and choose delete. This method is time-consuming and labor-intensive, so it is not highly recommended.Batch delete using SSH commands
This method is the fastest, but if the images inserted in your posts are thumbnails and not the original images, do not use this method. This method is only suitable forLinux VPS servers. If you are on shared hosting, this operation is not possible.
Use Xshell to connect to the server, then switch to the uploads folder and execute the following commands:find . -name '*-[0-9][0-9]x[0-9][0-9]*' 和 find . -name '*-[0-9][0-9][0-9]x[0-9][0-9][0-9]*'The two commands above are for finding files whose names contain „-numbernumberxnumbernumber“ and „-numbernumbernumberxnumbernumbernumber“. This is because WordPress thumbnail naming follows this format, for example, -75x75.jpg and -300x193.png as shown in the image above. After finding them and confirming these files can be deleted, use the following command to delete them:
find . -name '*-[0-9][0-9]x[0-9][0-9]*' -exec rm -f {} \;
和
find . -name '*-[0-9][0-9][0-9]x[0-9][0-9][0-9]*' -exec rm -f {} \;Another command found online that can utilize options-regexto use regular expressions:find . -regex '\./[0-9]+_[0-9]+\.zip'If you need to delete the found files, usexargs(Make sure before deleting):find . -regex '\./[0-9]+_[0-9]+\.zip'|xargs rm -fIf you not only want to delete but also get the count of deletions, you can do this:find . -regex '\./[0-9]+_[0-9]+\.zip'|tee >(wc -l 1>&2)|xargs rm -fAlright, the several methods introduced above can help youbatch delete WordPress thumbnails. Finally, a reminder again: please back up before operation to avoid deleting useful files.
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.