Ubuntu – gsettings – change privacy settings via command line

command linedconfgsettingsprivacy

I know how to change privacy settings via GUI (System Settings > Security & Privacy), but I'd like to be able to do it from command line.

What I did to find out

I ran the command:

dconf watch /

to see what changes were made. About the command (from man dconf):

watch
    Watch a key or directory for changes.

Subsequently, I changed settings via GUI to see what happened in the output of the command. It showed:

/org/gnome/desktop/privacy/remember-recent-files false
/com/canonical/unity/lenses/remote-content-search 'none'
/org/gnome/desktop/screensaver/ubuntu-lock-on-suspend false
/org/gnome/desktop/screensaver/lock-enabled false

My question is: how can I use this information to change the settings from command line?

Best Answer

Different ways to edit those settings

The settings you mention are stored in the dconf database in ~/.config/dconf (in binary format). This database can either be directly edited with dconf, or via gsettings. The difference is explained at the last section of this answer.

Once you have the information, posted in your question, you can therefore change the corresponding settings in two different ways.
Using your first example (setting remember-recent-files):

using dconf write:

dconf write /org/gnome/desktop/privacy/remember-recent-files false

or

using gsettings set:

gsettings set org.gnome.desktop.privacy remember-recent-files false

Similarly, reading the current setting:

using dconf read:

dconf read /org/gnome/desktop/privacy/remember-recent-files

or

using gsettings get:

gsettings get org.gnome.desktop.privacy remember-recent-files

In the first case, you edit the dconf database directly, in the latter you are using gsettings, which is a CLI frontend to dconf.

Which way to prefer; dconf or gsettings?

To protect the integrity of your dconf database, in general, it is considered better practice to use gsettings.

Frome this link, we read:

The dconf program can perform various operations on a dconf database, such as reading or writing individual values or entire directories. This tool operates on dconf directly, without using gsettings schema information. Therefore, it cannot perform type and consistency checks on values. The gsettings(1) utility is an alternative if such checks are needed. You can see gsettings as the cli-frontside to dconf.

Read more on gsettings and dconf.