Is it possible to delete a file not in usage outside of the context of a field widget in Drupal 8?

I tried to find a route like admin/file/{file}/delete but don't really see anything in the file module to do this operation.

I found this issue, which I assume is related. So the question remains: How can you delete files? I've set "delete orphaned files after" to Never in the admin so that files are not mistakenly deleted, which has happened to me a few months ago.

3 Answers 3


There is no functionality for this in core in the UI. You could do a entity load + delete with drush ev/core-cli or console, but that's basically your only option.

File entity does offer a UI for this, but you possibly don't want to use it anymore.

That said, setting that setting to Never is IMHO the wrong solution, as it also doesn't delete files that were only uploaded but then for example removed again or never really submitted. See https://www.drupal.org/node/2801777 for more information and another solution for that.

That said, when using media_entity, it should be save to configure Drupal to delete unused files as the media entity itself will always count as a usage of the file, so it will only ever get deleted if you manually delete a media entity.

  • This is just core file upload module. I had to set it to never after a good chunk of my files (on disk) were deleted without explanation with no way to recover them.
    – Kevin
    Feb 22, 2017 at 21:39

I wound up creating a solution so I wouldn't have to worry about file paths anymore, which removed the need to explicitly control the file being deleted.

Media Entity Download

Now I can set the system back to deleting orphaned files, my actual drive here was to preserve the file url (sites/default/files/foo.pdf) from ever changing, which introduces this conundrum.


Contributed Drupal module Views Bulk Operations has D8 Beta release which can help.

Install the module, edit Files view, add "Views bulk operations" global field and configure it to include "Delete selected entities" action.

The module is currently limited from an Admin point of view as it only allows the person that uploaded the file to execute the delete. Trying to do it as anyone else (including user-1) will fail (with log error message). Hopefully this limitation will be fixed in releases to come.

  • I don't understand such kind of down voting. Without any comment, without explanation... just down vote. Not very useful.
    – devad
    Dec 29, 2017 at 18:55
  • first off you seem to be posting this same comment/answer on any post relating to the need to delete Drupal files. E.g. drupal.stackexchange.com/questions/236809/… Secondly your solution only works if you are the file owner, as I stated in the above link.
    – John Cogan
    Feb 14, 2018 at 9:33
  • @john-cogan Thnx for reply. I have included module limitation in my answer. Regarding multi-posting... there is nothing wrong with posting the same answer if the answer is relevant to all the questions.
    – devad
    Feb 15, 2018 at 14:01

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.