How to update internal-links in bulk

I want to add UIDs to my notes filename in bulk, but I don’t know how to update the internal-links in the file while modifying them.

I know Obsidian provides a feature to update the links automatically, but it seems to need to modify the file names one by one manually, is there any other way?

1 Like

You didn’t mention what platform, but it’s something you could do outside of Obsidian. Start by making a copy of your vault and apply the method to the copy. If you’re on Linux/macOS (my world) the process is as follows. In theory the same thing could be done on Windows with Windows Subsystem for Linux.

I assume you mean all of your notes. First get a stream of all of your notes in the vault tree:

find vaultDir -type f

Use this stream to process each file name. The general process would be to copy the original note to the new modified note name with the UID. Then scan the other files for links to the old note name:

grep -roI ‘\[\[filename’ testVault|cut -d : -f 1|sort -u

Don’t pick up the note you’re currently working. This will give you a list of files referencing the old note name as an outbound link. Now pipe this through a command to change all references:

sed ‘s/\[\[oldfilename/\[\[newfilename/g’ < currentfile > currentfile.changed
mv currentfile.changed currentfile

Then the old note name without the UID can be removed. This can all be glommed together in a single script that will do it.

Then open the new vault and check it. You could also recursively diff the files in each vault to verify it only changed the link references before you commit to the new vault.