I want to add bookmarks to nautilus via the command line. These bookmarks can be directories on the boot drive or auto mounted external drives. I want to know how to do this from the command line instead of doing it manually via the GUI.

The reason I want to do this is every one or two months, I, a linux newcomer, use sudo too liberally or run into a problem that I don't know how to fix and end up having to reinstall my operating system. I've written a shell script that reinstalls my programs and now I want that script to do some configuring.


Nautilus bookmarks are stored in a plain text file ~/.config/gtk-3.0/bookmarks. You can therefore easily add or remove lines from the file with the usual shell tricks to add or delete lines.

The format of the file is at the minimum the URI of the target, e.g. file:///home/login/Documents/Letters, or smb://files.server/scans. Special characters in this URI should be URI-encoded, e.g. a space should be represented as %20. After a space, you can add the label that should be displayed in Nautilus. Otherwise, the basename will be displayed.

Add lines with something like:

echo "file:///home/login/Documents/Letters" >> ~/.config/gtk-3.0/bookmarks

or

printf %s "file:///home/login/Documents/Letters" >> ~/.config/gtk-3.0/bookmarks

Delete lines with for example

sed -i '/Documents\/Letters/d' ~/.config/gtk-3.0/bookmarks

or

cat ~/.config/gtk-3.0/bookmarks | grep -v '/Documents/Letters' | tee ~/.config/gtk-3.0/bookmarks