tmpfiles.d – “x”和“X”选项的区别?

我在CentOS 7上configuration了tmp cleanup。在解释tmp.conf中的Xx选项之间的区别时,tmpfiles的文档有点不清楚。 根据文档的不同在于,使用X选项,

x不同,如果path是一个目录,那么这个参数不会排除这个内容,而只是目录本身。

我不知道如何解释这一点。

基本上我有一个生活在/tmp ,我不想被删除(包括其内容)。 为此,添加一行就足够了

 x /tmp/myspecialdir 

/usr/lib/tmpfiles.d/tmp.conf

我也发现这很混乱。 这是一个简单的例子。 我认为如果你在一个特定的目录下有一个深层的树,而你想删除一些而不是所有的目录,那么x和X就会变得有用。

这里是我的exclude.conf: root# cat /etc/tmpfiles.d/exclude.conf d /tmp/testdir 0755 root root 1s x /tmp/testdir/*

现在我创build一些目录: # mkdir /tmp/testdir/a ; mkdir /tmp/testdir/b; mkdir /tmp/testdir/ab # mkdir /tmp/testdir/a ; mkdir /tmp/testdir/b; mkdir /tmp/testdir/ab

# ls -lrt /tmp/testdir/ total 0 drwxr-xr-x. 2 root root 6 Sep 1 12:55 a drwxr-xr-x. 2 root root 6 Sep 1 12:55 b drwxr-xr-x. 2 root root 6 Sep 1 12:55 ab # ls -lrt /tmp/testdir/ total 0 drwxr-xr-x. 2 root root 6 Sep 1 12:55 a drwxr-xr-x. 2 root root 6 Sep 1 12:55 b drwxr-xr-x. 2 root root 6 Sep 1 12:55 ab运行干净

#systemd-tmpfiles --clean exclude.conf

检查

# ls -lrt /tmp/testdir total 0 drwxr-xr-x. 2 root root 6 Sep 1 12:55 a drwxr-xr-x. 2 root root 6 Sep 1 12:55 b drwxr-xr-x. 2 root root 6 Sep 1 12:55 ab

现在,如果执行X /tmp/testdir/* ,我会得到相同的结果。 然后,如果我有x /tmp/testdir/b ,那么它将从清理中排除“b”目录。

#systemd-tmpfiles --clean exclude.conf

# ls -lrt /tmp/testdir/ total 0 drwxr-xr-x. 2 root root 6 Sep 1 12:55 b # ls -lrt /tmp/testdir/ total 0 drwxr-xr-x. 2 root root 6 Sep 1 12:55 b另外, X /tmp/testdir/b显示相同的行为。 但是, X /tmp/testdir/x /tmp/testdir会删除x /tmp/testdir所有子目录,但会保留testdir

我build议在设置之前testing一下设置。 我的手册页可能会更清晰一点。