How to find the unused media out and delete them?

Hello everyone I’m here to ask questions again! Sometimes I add an image then decide to change/remove it. However, it doesn’t get deleted from the group. All the unused images could pile up and take up space in the cloud. Any idea about how to find the unused media out and delete them?

Is this an indexed image, how did you try to delete it?

Some image‘s link is deleted in the body after I add image to the MD file, but it also stays inside the folder, so that I can’t tell which images in the folder are used in the body and which are not. Most of my MD files’s images are created with “![]()” syntax, so there seems to be no way to display the outgoing links icons. :neutral_face:

This problem could be solved by a shell script, I think:

cd md-dir # the folder where the MD file and images are stored
for i in `ls *.jpg`; do # loop over the jpg images in this folder, adjust for other images
  grep -q "$i" index.md || echo "$i not used" # check if the name of the current image file is used in the md-file
done

Not tested, of course, but something along these lines should do the trick. Not a DT question at all, though.

:sweat_smile: I may need a little time to figure out how this works.

Astonishingly, the script even works and does what it’s supposed to to. I just tried it out with one of my collections of MD and image files and it complained correctly about the only image not used in the MD file. You’d have to adjust the name of the MD file, though, or use

grep -q "$i" *.md

Sorry to interrupt, emm… this is the need to use “terminal” this app? :thinking:

Yes. But I can assure that that the terminal app does not bite, contrary to the popular belief of many Mac users. And in this case no single command does anything to your files or folders: grep is just scanning them (aka “read”), ls produces a list of all files ending in .jpg, and echo does what it says.

T-T… All I know is that I have to type “cd” and a space in the terminal, then drag the target folder in and hit enter. Do I type in every line after that?

I think this is the moment to use a search engine of your preference. All this is completely off-topic here.

Sorry, indeed! Thanks for your reply! But since DT already has such a nice feature as outgoing link and incoming link, it would be a great convenience for users like me who are not familiar with scripts if we could go a step further and use small icons to display the linked images and other attachments!

That’s not what you were talking about before: You wanted to know which of the images where not used. How would DT know that, given that there might be another MD file that uses them? Why would it even bother? E.g., I have scaled down images stored together with my MD files that are never referenced im them. I would certainly not want my ME editor to tell me about them.

It’s true that I didn’t think it through enough, and you’re right, some images don’t need to be linked by any notes, but it’s also valuable to keep, but for images that are present in a certain notes folder, if it’s not linked by any notes, it means it’s most likely a useless image attachment. Just like the outgoing link and incoming link icons, it is enough to play a role as a marker, and it is up to the user to choose whether to delete it or not.