XDG directories

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

The XDG directories are standard directories specified by freedesktop.org (formerly the X Desktop Group).

Directories

The XDG Base Directory Specification defines:

  • XDG_DATA_HOME: the base directory relative to which user-specific data files should be stored. If not set, or empty, assumed to be $HOME/.local/share/.
  • XDG_DATA_DIRS: the preference-ordered set of base directories, separated by colons (':'), to search for data files in addition to the XDG_DATA_HOME base directory. If not set or empty, assumed to be /usr/local/share/:/usr/share/.
  • XDG_CONFIG_HOME: the base directory relative to which user-specific configuration files should be stored. If not set, or empty, assumed to be $HOME/.config/.
  • XDG_CONFIG_DIRS: the preference-ordered set of base directories, separated by colons (':'), to search for configuration files in addition to the XDG_CONFIG_HOME base directory. If not set or empty, assumed to be /etc/xdg/.
  • XDG_STATE_HOME: the base directory relative to which user-specific state files should be stored, containing data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in XDG_DATA_HOME. If not set, or empty, assumed to be $HOME/.local/state/.
  • XDG_CACHE_HOME: the base directory relative to which user-specific non-essential data files should be stored. If not set or empty, assumed to be $HOME/.cache/.
  • XDG_RUNTIME_DIR: the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, who MUST be the only one having read and write access to it; its permissions MUST be 0700.
  • $HOME/.local/bin/: the directory for user-specific executable files.

Normally, the XDG_* variables will be set appropriately by systemd or elogind upon login. On systems not using either, it might be necessary to configure them manually, e.g. in one's .bash_profile file or equivalent:

FILE ~/.bash_profile
export XDG_CONFIG_HOME="${HOME}/.config/"
export XDG_DATA_HOME="${HOME}/.local/share/"
if [ -z "${XDG_RUNTIME_DIR}" ]; then
     export XDG_RUNTIME_DIR="/tmp/${UID}-runtime-dir/"
     if [ ! -d "${XDG_RUNTIME_DIR}" ]; then
         mkdir "${XDG_RUNTIME_DIR}"
         chmod 0700 "${XDG_RUNTIME_DIR}"
     fi
fi