17

I've seen these directories being used by many applications and am now considering using them for my app. How do I know this is an officially supported folder and not just a flavor of the month location for a per-user cache/config?

I've been searching for something official from Ubuntu but to no avail; maybe someone else knows the proper search terms or location of this documentation. Is this something I should just accept as an un-stated standard practice location?

4
  • @Nmath They're not "hidden" really. It's just a "traditional" Unix design ( or oopsie ) where ls would ignore dot files and other applications sort of adopted it, but they're in no way hidden, and shouldn't be used as security feature in any way. Rob Pike, one of the Unix wizzards, has also clarified that originally the purpose was to hide . and .. directories from the output, but that was implemented in a wrong fashion. Read about it here: askubuntu.com/a/1073810/295286 Jun 17, 2019 at 19:22
  • @Nmath Well, even accidental deletion can happen with these. Consider the find command or Python for example - these don't ignore dotfiles by default. I agree that it may be convenient to remove them from listing to the end-user, but that's about it. Jun 17, 2019 at 21:22
  • 4
    @SergiyKolodyazhnyy few methods are 100% effective on their own. As far as claiming that dotfiles are "in no way hidden" is demonstrably false, since that is the main reason they are used and the only benefit for adding the preceding .. Are they totally invisible? No, and they shouldn't be. Can they still be read/written? Yes, and they should. Are they invisible (hidden) in most cases? Yes -- that's the point
    – Nmath
    Jun 17, 2019 at 21:26
  • 1
    @Nmath Well, let's just agree to disagree :) Besides comment section isn't for extensive discussions. Jun 17, 2019 at 22:20

1 Answer 1

25

Yes, there is a standard: these are specified by freedesktop.org and are part of XDG Base Directory Specifications.

config-spec outlines just basic requirements, but the details are in the Base Directory Specifications. The ~/.config and ~/.cache directories are default unless configured otherwise:

There is a set of preference ordered base directories relative to which configuration files should be searched. This set of directories is defined by the environment variable $XDG_CONFIG_DIRS.

There is a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.

...

$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.

...

$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.

You may notice these specifications mostly state where data should be stored, which environment variables used, and in what manner ( desktop-neutral, efficient, etc ), but most desktops are free in implementing the "how" part of it. The GNOME-based desktops will use gsettings where as KDE users can use the same via kwriteconfig, but they both will rely on ~/.config directory in the process


Question key points

How do I know this is an officially supported folder and not just a flavor of the month location for a per-user cache/config?

These directories appear in official documentation and Filesystem Hierarchy Standard also mentions them. This is official documentation, hence the folders are officially supported.

Is this something I should just accept as an un-stated standard practice location?

Depends on the app you're creating. Is the app supposed to be configurable on per-user basis or work consistently through out the system ? FHS tells us that for system-wide stuff we should use /etc or /usr/local, but XDG directories should be used for user-specific configurations - ~/.cache and ~/.config. Of course, if application isn't dependent on user-specific settings, /var/cache can be used instead of per-user directory. Of course, you could always have single ~/.appname.conf file, a ~/.appname.db or ~/.appname/ directory to keep configurations and cache there, but that would be non-standard; not "bad" - just non-standard.

See also

3
  • Ah awesome, I should have dug deeper, thanks for the information.
    – Danny A
    Jun 17, 2019 at 20:21
  • Which part of POSIX talks about directory usage?
    – chepner
    Jun 18, 2019 at 3:38
  • @chepner I originally though POSIX did but after reviewing a few pages, it doesn't seem so. There's Directory Structure and Devices though it does not specify /etc. There are mentions of /etc/passwd in link and unlink syscall specifications, but beyond that - no definition of what /etc/ should be used for. Thanks for the question, it helped finding a few extra links Jun 18, 2019 at 5:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .