Score:2

Add Bookmarks to Nautilus via Terminal

ru flag

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.

vanadium avatar
cn flag
It is a valid question to want to create bookmarks via the command line without providing this stupid reason that you "use sudo too liberally", apparently without the intention to change this unthoughtful behaviour.
pLumo avatar
in flag
@vanadium, you are right. However, having a decent backup recovery mechanism is a good thing ;-)
Score:1
cn flag

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
pLumo avatar
in flag
This -> `location=/path/to/dir; name=some_name; printf 'file://%s %s' "$location" "$name'' >> ~/.config/gtk-3.0/bookmarks`
hmontoliu avatar
it flag
Great answer, thanks
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.