DEV Community

Cover image for How to un-trash Obsidian attachments
Michal Bryxí
Michal Bryxí

Posted on

How to un-trash Obsidian attachments

For some reason I'm finding following files in my Obsidian vault attachment folder:

Attachment/.trashed-1715241915-BB_LIMBA4.webp
Attachment/.trashed-1716527209-2018 Global shipping cargo by weight.jpeg
Attachment/.trashed-1716527209-7f8c7729e62a9d0703b8ad3ce175a924-493788641.jpg
Attachment/.trashed-1716527209-Drivers of forest loss in the Brazilian Amazon.png
Enter fullscreen mode Exit fullscreen mode

Those are legitimate files that should not be trashed. It might be a bug in Obsidian itself or just me doing something silly.

Either way if you need to restore those files, then following one-liner might help:

rename -n  "s/.trashed-\d*-//g" ./Attachment/.*
Enter fullscreen mode Exit fullscreen mode

Explanation of what is happening:

  • Assumption is that your working directory is inside your Obsidian vault.
  • Assumption is that your attachments are all stored in ./Attachment folder.
  • The -n switch will do a dry run, so nothing gets renamed yet, just prints out what would happen. Remove it once you are sure this is what you want.
  • The s/.trashed-\d*-//g part basically says "find part of the name that goes .trashed, dash, any amount of numbers, dash again. And replace all those characters with nothing.

Prerequisites

On OSX you need to install the rename tool first:

brew install rename
Enter fullscreen mode Exit fullscreen mode

Header image generated by ChatGPTv4 via prompt: Image of Comic trash eating computer files --ar 100:42

Top comments (0)