For most Linux distributions, even in a pristine bare minimum installation, the home directory of a user is already littered with a bunch of files and directories, that contain program configurations, colloquially called dot-files. This gets worse over time, as more programs are installed and used.
First of all, the visual clutter of a mass of dot-files and directories is heavily distracting. To get this visual clutter out of your way is big plus.
Second, organizing your data files in respect of data type helps running your backups faster and keeps your backup files smaller. I don’t find it particularly useful for my backups to include stuff like image thumbnails or my web browsers cache. In case of a data loss, such data is automatically reconstructed on the fly (i.e., image thumbnails) or not of much importance (i.e., a web browser’s cache).
The XDG Base Directory Specification defines a set of locations in a user’s home directory where programs should look for and place user specific files, i.e., configuration files, cache files, state files, runtime files, and application data. These locations are defined by environment variables that start with . All but one of these env vars have a default value, and can be set to user-specific values.
This blog article is rather a walk-through for how get an uncluttered home directory, and keep it uncluttered with the help of the XDG spec. There is an indepth introduction into the XDG Base Directory Specification in the techdoc section of this site.
The XDG base dirs perfectly suit the mission goal of an uncluttered, clean home directory. Unfortunately, getting an uncluttered, clean home directory in Linux is not a straight forward action. Adoption of the XDG Base Directory Specification by programmers that write tools and programs for *nices, respectively Linux, is pretty low.
For programs that follow the XDG base dir spec, the procedure is to read the respective env vars, and, in case the env var is not set or is empty, to use the respective default value defined in the XDG base dir spec. The spec does not define a default value for , which leaves little room for an arbitrary choice ( is a good choice for runtime files).
I always suspected that programs that don’t adhere to the XDG base dir spec just evaluate the env var and dump their stuff right into it. Until the xscreensaver man page told me so:
" ENVIRONMENT
....
HOME for the directory in which to read the .xscreensaver file. "
xscreensaver man page
There are a bunch of programs to configure XDG and read its configuration. I think these programs are an overkill.
All you need to do is to set the XDG env vars in your . Here is the XDG section of my as an example:
Most of the env vars listed above are self-explanatory, with a few exceptions:
In practice, I have never seen any program on my machine using the following locations: XDG_DOCUMENTS_DIR, XDG_TEMPLATES_DIR, XDG_PUBLICSHARE_DIR, XDG_MUSIC_DIR, XDG_PICTURES_DIR, XDG_VIDEOS_DIR. Not for decades. It might be different on your machine if you are using some heavy-weight desktop environment. But clearly, what’s the point of these directories? I have my templates and documents in directories for the topic, like or . And I do not see any point of having a MP3 collection in my home dir. That’s why I point all these env vars to .
There are three ways to get non-complaint programs to use the XDG base dirs:
Programs that dump all kind of data from config, cache and whatever right into or into a dir right in , can be confined to a kitchen sink directory with . I’m using for it. There are some benefits from this approach:
The XDG spec states that user specific executables are to be located in The notion in the XDG base dir spec that “Distributions should ensure this directory shows up in the UNIX $PATH environment variable, at an appropriate place.”, without the possibility for configuration of the user specific executable dir, is quite patronizing. I’m not a fan of user-specific executables anyway. is good enough for me. So far, I haven’t had .
Java programs use the location for user specific configuration (preferences in Java parlance). The default value for is . can be supplied to Java on the command line:
Java programs read on startup the env var and can pick up
from . can contain
one or more values, whereby the values are separated by
So, another option is to add the Java config dir to and then start java with the application JAR-file:
Putting the above two lines into a shell script has the following advantages:
xscreensaver man page, section Environment
Oracle Java SE 8 Documentation, The JAVA_TOOL_OPTIONS Environment Variable