![在 15.04 中使用 systemd 保留 /tmp 中的文件](https://linux22.com/image/1126049/%E5%9C%A8%2015.04%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20systemd%20%E4%BF%9D%E7%95%99%20%2Ftmp%20%E4%B8%AD%E7%9A%84%E6%96%87%E4%BB%B6.png)
如果可能的话,我希望在启动时保留 /tmp/foo/*。我尝试配置 tmpfiles.d,但没有成功。我以 root 身份创建了以下/etc/tmpfiles.d/foo.conf
内容:
x /tmp/foo/*
异或
X /tmp/foo - - - - -
异或
x /tmp/foo - - - - -
这些编辑均不起作用。
根据man tmpfiles.d
x 代表“在清理过程中忽略路径”,这正是我想要做的。在该手册页中甚至有一个关于如何实现这一点的示例 (#2)。
但是,重启后,/tmp/foo 总是丢失。我做错了什么?在 15.04 中,tmpfiles.d 是实现此目的的方法吗?
答案1
你需要这个:
x /tmp/foo - - - - -
但请注意:
Note that lines of this type do not influence the effect of r or R lines.
手册页:
r
Remove a file or directory if it exists. This may not be used to
remove non-empty directories, use R for that. Lines of this type
accept shell-style globs in place of normal path names. Does not
follow symlinks.
R
Recursively remove a path and all its subdirectories (if it is a
directory). Lines of this type accept shell-style globs in place of
normal path names. Does not follow symlinks.
x
Ignore a path during cleaning. Use this type to exclude paths from
clean-up as controlled with the Age parameter. Note that lines of this
type do not influence the effect of r or R lines. Lines of this type
accept shell-style globs in place of normal path names.
The configuration format is one line per path containing type, path,
mode, ownership, age, and argument fields:
#Type Path Mode UID GID Age Argument
d /run/user 0755 root root 10d -
L /tmp/foobar - - - - /dev/null
Fields may be enclosed within quotes and contain C-style escapes.