Remove unused attachments

Its hard to delete every attachment after deleting a file. And if there are lot of files in attachment folder its hard to find that specific attachment
Maybe while deleting file there should be pop up asking if user wants to delete attachments too


I’d like to see this as well. For example a button you could press and remove attachments that aren’t used.

This has previously been suggested as a plugin here: Delete unused media


I believe it would be extremely useful to have an option to remove all media associated with a note/file if there are not any active references to it in any other notes.

I tend to regularly drag images (screenshots, etc.) into notes when in meetings, and while I can certainly iterate over all files in the vault, grep for their presence in all of the notes, etc., that’s not necessarily something that all users will have the skills to do, or will even feel comfortable doing.


Use case or problem

There is a note. It has embedded files. These are usually images, possibly sound, etc.
Now, when you delete a note, all embedded files remain in the storage, which leads to a littering of the system

Proposed solution

You need an additional feature so that when you delete a note, the embedded files are also deleted

Current workaround (optional)

You have to delete these files manually.

Related feature requests (optional)


There should be an automagic way to remove orphan attachments.
I suggest the following: when deleting a note which contains the last link to an attachment, there should be a warning After deletion of this note the attachment ... will become orphan. Delete attachment ...? (Yes/No)


Same demands, that’s really a natual but missing feature.

I think my plugin find unlinked files is a good solution. It finds files (also attachments) which are nowhere linked (orphans) and lists them in an output file. With an extra command you can delete all files listed there with a certain extension. You can choose which extensions to delete in the settings. In this case it could be .jpg


This feature is critical for those who are bringing a large legacy database from Evernote (say) to markdown.

The .enex export contains a MYRIAD useful and useless files that were attached to the original HTML clippings, which are then imported to .md (using the life-saving application yarle).

My obsidian vault now contains 1000s of such useless files linked from the _resources folder to the .md files, and as I clean up the HTML advertising and recirculation tags in the .md files, they are all just lying there in _resources.

Any such feature rollout should (ideallly) not only delete orphans as they form, BUT be able to delete legacy orphan files (such as mine).



I would like to check before deleting, so I hoped for creating a Dataview, but that plugin seems unable to see anything apart from *.md:

from "Anhänge"

Dataview: Query returned 0 results.

(where “Anhänge” is just the German word for “attachments”).

1 Like

This is a very useful plugin. I store all my screenshots in a central assets folder. Over time, it accumulates quite a few orphans. This plugin did a great job identifying the orphaned jpg files and deleting them from my central assets folder.

1 Like

I made a fix for this. In the following example, we will remove all the excalidraw drawings that are not linked by another note.

Make a note with the title “Delete excalidraw orphans” and the following body:

dv.list(dv.pages().file.where(f =>"Drawing ") &&"excalidraw")).where(f => f.inlinks == 0 && f.outlinks == 0) => "<%+ tp.user.delete_file({FILE_TO_REMOVE:'"+path+"'}) %>"))

Make a user command using (python in my case) that will delete the files:

#!/usr/bin/env python3

import os

if == 'nt':
    vault_root_dir = "D:/GOOGLE DRIVE/OBSIDIAN/NOTES"

os.remove(os.path.join(vault_root_dir, os.environ['FILE_TO_REMOVE']))

Just for reference, my user command in the templater config is:

Now whenever you render the note, your orphan excalidraw drawings will be autoremoved.
Now I would like to run this as a single command instead of having to render the note so I can put it fully into a template (So this can be called via the templates menu instead of having to go to the note and render it).
Hopefully someone here knows how to do that :slight_smile:

Ok, I simplified this a lot, you just need to run the following template and your files will be deleted:


const dv =["dataview"].api
const filesArray = dv.pages().file.where(f =>"Drawing ") &&"excalidraw")).where(f => f.inlinks == 0 && f.outlinks == 0).path => {
tp.user.delete_file({FILE_TO_REMOVE: path})


Recently testing Obsidian and came here for this. Couple of thoughts:

  1. For removing previously orphaned files, I think the plugin is fine.
  2. Upon note deletion, removal of orphaned attachments should absolutely be core functionality.

Fully agree with everyone that believes removal of attachments should be done automatically upon deleting the note its attached too.

I’d also wish to have such a feature.
It would be really usefull, when there’s a popup window when deleting a note, so one can decide whether to delete the attachment, too.

1 Like

Please add this feature.

The feature is a must.

Useful idea

Yes this needs to be implemented

Huh. I thought that dataview couldn’t list pages that were not Markdown: List other filetypes in vault · Issue #234 · blacksmithgu/obsidian-dataview · GitHub

So how can"excalidraw") this ever work? Or maybe this somehow works for *.excalidraw but not *.pdf?