Вопрос

I'd like to cache some files in $HOME/.cache, but I don't know under what OSes I can assume that it already exists. Can I try to create it myself if it does not, or is that an error? What entity creates it? Is the location of .cache standardized and by what standard?

Это было полезно?

Решение

(Linux) File System Hierarchy

The linux file system hierarchy (man hier) does not imply any $HOME/.cache directory. From that man page, highlighting added by me:

/home

On machines with home directories for users, these are usually beneath this directory, directly or not. The structure of this directory depends on local administration decisions.

freedesktop.org Specifications

The .config and .cache directories are specified by freedesktop.org as reasonable defaults to the environment variables $XDG_CONFIG_HOME and $XDG_CACHE_HOME. Quoted from these specifications, again highlighting is added by me:

$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.

To follow their specifications, you might want to read $XDG_CACHE_HOME first, and if not set use $HOME/.cache and create it, if necessary. You will very often encounter these variables not set – in fact, it is not set on any of my machines.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top