我想在 $HOME/.cache
中缓存一些文件,但我不知道在什么操作系统下我可以假设它已经存在。如果没有,我可以尝试自己创建它吗,或者这是一个错误?什么实体创造它? .cache
的位置是标准化的吗?按照什么标准?
最佳答案
(Linux) 文件系统层次结构
Linux file system hierarchy (man hier
)并不意味着任何 $HOME/.cache
目录。从那个手册页,我添加了突出显示:
/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 规范
.config
和.cache
目录是specified by freedesktop.org as reasonable defaults到环境变量 $XDG_CONFIG_HOME
和 $XDG_CACHE_HOME
。引用自这些规范,再次突出显示是我添加的:
$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.
要遵循他们的规范,您可能需要先阅读 $XDG_CACHE_HOME
,如果未设置,请使用 $HOME/.cache
并在必要时创建它。您会经常遇到这些未设置的变量——事实上,它在我的任何一台机器上都没有设置。
关于linux - 我可以假设 .cache 目录存在吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22742923/