Bulk edit YAML in Obsidian files
In December 2025, I started using the Digital Garden plug-in for Obsidian, but there are private files I want to have some safeguard of not publishing. I stumbled on yq, a YAML command-line tool. Here's an example of editing the front-matter of a Markdown file with the tool, where we add a tag with a value:
yq --front-matter=process '.dg-publish = false' -i example.md
-f is a shortcut for --front-matter, which takes two operations: process and extract. Extract just prints the front matter without modification.
Add a missing tag without duplication
Sometimes we need to add an item to a list. This one-liner will add "programming" to the "tags" array, then remove duplicates.
find . -name "*.md" -exec yq -f process '.tags = ((.tags // []) + ["programming"] | unique)' -i {} \;
(.tags // []) ensures the tags array exists, unique performs the de-duplication. See yq documentation for all the operators.
Conditional add based on existence of another tag
Here, we add the "moc-folder" tag to any file with the "MOC" tag. This code goes the extra mile, working if tags is a list or a scalar value.
find . -name '*.md' -print0 | \
while IFS= read -r -d '' f; do
if yq eval -f=process '.tags[]' "$f" 2>/dev/null | grep -iqx 'moc' || \
yq eval -f=process '.tags' "$f" 2>/dev/null | grep -iqx 'moc'
then
echo "Updating: $f"
yq eval -i -f=process '.tags += ["moc-folder"] | .tags |= unique' "$f"
fi
done
Removing a tag
This is but one method, I chose select here because it's more flexible than just tag names.
find . -name "*.md" -exec yq -f process '.tags = (.tags // [] | map(select(. != "board-game")))' -i {} \;
Toggle value: turn off dg-publish
Batch processing is easy with standard ZSH commands. From the top-level folder with the private content, I ran:
find . -name "*.md" -exec yq -f process '.dg-publish = false' -i {} \;
Now, even if there's a link to one of the items in the folder, the Digital Garden Publishing Center won't suggest publishing it.
I now accomplish this goal in a different way, within 11ty, see Prevent publishing of notes in a folder.