How to change Linux desktop user directories

From Leo's Notes
Last edited on 18 August 2023, at 21:55.

Linux desktop managers such as GNOME and KDE use XDG (aka the X Desktop Group) to manage 'well known' user directory locations such as the typical Desktop, Downloads, Pictures, Music, etc. directories that appear in your home directory. XDG also handles the localization of these directory names so that these directories show up in the user's preferred language.

If you need to change the desktop location from ~/Desktop to somewhere else such as ~/Other-Desktop, edit ~/.config/user-dirs.dirs:

# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.

Alternatively, you can use the xdg-user-dirs-update command to update the path:

# xdg-user-dirs-update --set DESKTOP ~/Other-Desktop

Querying XDG directory paths[edit | edit source]

Use the xdg-user-dir command to get the full path to a specific XDG directory. For example:

# xdg-user-dir DESKTOP

According to ArchLinux, you must sanitize the arguments to this command or risk arbitrary code execution.

See also[edit | edit source]