I have thousands of unattached images with no files. How do I delete them all quickly?

ls: cannot access wp-content/uploads/2014/09/jeep cherokee patriot-Ekza.jpg: No such file or directory

  • I ended up using SQL and shell commands to remove them all. I selected all the unattached attachments into a file, used a for loop to list then remove the file, then deleted the rows from the database. I wish I saved the SQL and command line.
    – Chloe
    Oct 16, 2014 at 0:02
  • 2
    Could you please share the code you used? I am about to do the same thing. If you still have access to that database command line, then it would be in the history.
    – user658182
    Apr 7, 2017 at 13:27
  • I want to have this code as well, can you please share it? Mar 1, 2018 at 15:25
  • Sounds like a job for the wp-cli command-line, see eg answers here wordpress.stackexchange.com/q/262823/26350
    – birgire
    Aug 13, 2023 at 4:50

2 Answers 2


That's a lot of unattached images. If you have couple of hundred images then you can delete them manually from media library.

1. Click 'Screen Options' at the top right and set 'Show on screen' to 200.
2. Click 'Apply'.
3. Click the checkbox just under 'Bulk Actions' to check all images on the page.
4. Select 'Delete Permanently' in the 'Bulk Actions' dropdown.
5. Click 'Apply'.

But if you have thousand of unattached images then it would be best to use a plugin. DNUI (Delete not used image) plugin will do that for you. It will let you delete tons of images from media library.

Or use DX Delete Attached Media

  • My dashboard looks like this, I don't see any screen options.
    – Suncatcher
    May 12, 2018 at 15:57
  • @Suncatcher I had the same issue. You need to change to "list"-view beforehand. Then you have the screen options. It's much easier to delete the files like this Aug 12, 2020 at 11:51
  • DNUI (Delete not used image) plugin: This plugin has been closed as of January 10, 2023 and is not available for download. Reason: Security Issue.
    – sotirov
    Aug 2, 2023 at 21:25

There are many tools/plugins now in the repository.

You can check out these two:



Out of these two, I find the first one to be more thorough and has more capability. The second one is good, but you need to pay for a pro license to get the same features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.