How to change Linux desktop user directories
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.
#
XDG_DESKTOP_DIR="$HOME/Other-Desktop"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_VIDEOS_DIR="$HOME/Videos"
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
Use the xdg-user-dir
command to get the full path to a specific XDG directory. For example:
# xdg-user-dir DESKTOP
/home/leo/Desktop
According to ArchLinux, you must sanitize the arguments to this command or risk arbitrary code execution.