xdg-user-dir
Get standard user directories
TLDR
Display the home directory for the current user
Display the location of a user directory
SYNOPSIS
xdg-user-dir [OPTION...] DIRECTORY_NAME
PARAMETERS
DIRECTORY_NAME
Specifies the well-known user directory type to query (e.g., DESKTOP, DOWNLOAD, DOCUMENTS, MUSIC, PICTURES, VIDEOS, TEMPLATES, PUBLICSHARE).
-h, --help
Displays a brief help message and exits.
--version
Shows the version information of the xdg-user-dir utility and exits.
DESCRIPTION
xdg-user-dir is a utility provided by the XDG (FreeDesktop.org) project to query the paths of standard user directories. These directories include common locations like Desktop, Documents, Downloads, Music, Pictures, and Videos. The command ensures applications can reliably locate these user-specific directories, promoting consistency and interoperability across different desktop environments and distributions. It achieves this by reading the configuration from the ~/.config/user-dirs.dirs file, which maps logical directory names (e.g., "DESKTOP") to their actual file system paths (e.g., "/home/user/Desktop"). If the configuration file is missing or a specific directory is not defined, xdg-user-dir typically falls back to a sensible default path within the user's home directory. This standardization helps developers avoid hardcoding paths and allows users to customize their directory locations easily.
CAVEATS
xdg-user-dir primarily reports paths; it does not automatically create missing directories. Use xdg-user-dirs-update to ensure directories exist and are properly configured.
The DIRECTORY_NAME argument is case-sensitive (e.g., "DOWNLOAD" is valid, "download" is not).
Relies on the presence and correct format of the ~/.config/user-dirs.dirs file. If this file is absent or malformed, default paths may be returned, or the command might not function as expected.
CONFIGURATION FILE
The paths returned by xdg-user-dir are primarily configured in the user-specific file: ~/.config/user-dirs.dirs. This file contains key-value pairs linking logical directory names to their absolute paths, for example:
XDG_DOWNLOAD_DIR="$HOME/Downloads"
Users can manually edit this file, though it is commonly managed and updated by the xdg-user-dirs-update command.
COMMON DIRECTORY NAMES
The most frequently queried DIRECTORY_NAME values include:
DESKTOP: The user's desktop directory.
DOWNLOAD: The directory for downloaded files.
DOCUMENTS: The directory for user documents.
MUSIC: The directory for music files.
PICTURES: The directory for image files.
VIDEOS: The directory for video files.
TEMPLATES: The directory for document templates.
PUBLICSHARE: The directory for publicly shared files.
HISTORY
xdg-user-dir is part of the xdg-user-dirs package, which originated from the FreeDesktop.org (now XDG) initiative. This initiative aims to standardize various aspects of the Linux desktop environment, including directory structures. The tool was developed to address the inconsistency of user directory locations across different desktop environments and distributions, providing a robust and portable way for applications to find common user directories since the early 2000s.
SEE ALSO
xdg-user-dirs-update(1), xdg-open(1), xdg-mime(1)