13

I've see 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 Googling and 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?

  • "maybe someone else knows the proper search terms": I'm not sure of official documentation for their use but these are considered dotfiles, more specifically dotfolders in those examples. They are hidden by default and are commonly used for saving user preferences (~/.config) and other "support" files like cache (~/.cache). – Nmath Jun 17 at 19:12
  • 2
    "official from Ubuntu" wrong place. It is defined by the freedesktop organization so -desktop- dependent. Not just Ubuntu. Oh and these are GUIDELINES. – Rinzwind Jun 17 at 19:23
  • 1
    @SergiyKolodyazhnyy it is interesting to discuss the history of how dotfiles came to be, but in practice dotfiles/dotfolders are hidden (not visible) by default by file managers and bash commands like dir. In that way, yes they are absolutely "hidden". Hiding files this way serves a good purpose to prevent them from being accidentally altered/deleted by end user -- that's why they are still used so ubiquitously. I agree that dotfiles should not be used for security, in the sense that they are not impossible to find/read/alter. – Nmath Jun 17 at 21:15
  • 3
    @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 at 21:26
  • 1
    @Nmath Well, let's just agree to disagree :) Besides comment section isn't for extensive discussions. – Sergiy Kolodyazhnyy Jun 17 at 22:20
18

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

  • ehm did you post this before me? or during? >:) – Rinzwind Jun 17 at 19:24
  • @Rinzwind Right before your answer :) Look at the time line askubuntu.com/posts/1151791/timeline – Sergiy Kolodyazhnyy Jun 17 at 19:27
  • Ill let you have this one :=) – Rinzwind Jun 17 at 19:47
  • Ah awesome, I should have dug deeper, thanks for the information. – Danny A Jun 17 at 20:21
  • Which part of POSIX talks about directory usage? – chepner Jun 18 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.