Getting acquainted with XDG(freedesktop) on Linux

Understanding XDG Specifications and their importance

I stumbled upon XDG while working on an issue for a CLI tool in the past. It required a background on what XDG is and it’s specification. With a little bit of “googling” I was able to find the specification but I was still a bit confused as to what the hell XDG is and was frustrated that there is no concise article for it.

Somewhere, someone had said, “If there is something that you want to read and it doesn’t exist, write it yourself.” So here goes.

What is XDG ?

Quoting from the wikipedia page, was formerly known as the X Desktop Group, and the abbreviation “XDG” remains common in their work.

Now we know that XDG is just another name for the But what is ? hosts the development of free and open source software, focused on interoperability and shared technology for open-source graphical and desktop systems. We do not ourselves produce a desktop, but we aim to help others to do so.

So, it is a collaboration zone for “interoperability and shared technology for open-source graphical and desktop systems”. Some of the more popular projects hosted by XDG are Wayland, PulseAudio and systemd.

The Portland Project

Apart from sounding like a great name for a highschool garage band, The Portland Project was an initiative aimed at portable application software between desktop environments and kernels and hence strengthen the appeal of Linux as a Desktop Environment and not just for basement dwellers like some of us who refuse to deal with the capitalist technocrat folks of the Operating Systems world.

xdg-utils is the more well known name for the project and it is basically

a set of tools that allows applications to easily integrate with the desktop environment of the user, regardless of the specific desktop environment that the user runs.

Relevant Specifications by XDG

These specifications are important as they form the base for tools in xdg-utils and are a staple of Linux distributions today.

Some specifications one can start with are the Base Directory and the Desktop Entry Specifications. We are only covering the Base Directory Specification as it helps a ton to understand it while creating consistent applications across Linux Environments (great to know while building Command Line Interfaces for Linux).

XDG Base Directory Specification

Defines the Configuration for Base Directories and the defaulted location of files based on their usage so that not everything is stored in the same place by default.

This specification outlines that the user-specific data, the configuration files and cache files for a particular application need to be segregated and each of their locations need to be defined by an environment variable.

User Specific Data should be in $XDG_DATA_HOME (default to $HOME/.local/share)

Configuration files should be in $XDG_CONFIG_HOME (default to $HOME/.config)

Cache files in $XDG_CACHE_HOME (default $HOME/.cache)

Then there are other environment variables which are more of aggregators which help for searching the locations in different places.

Multiple locations for Configuration files given in $XDG_CONFIG_DIRS (includes $XDG_CONFIG_HOME)

Multiple locations for Data files $XDG_DATA_DIRS (includes $XDG_DATA_HOME)

Constructions and Abstractions.