I'm configuring tmp cleanup on CentOS 7. The docs for tmpfiles are a little unclear to me when explaining the difference between the X
and x
options in tmp.conf
. The difference according to the docs is that with the X
option,
Unlike
x
, this parameter will not exclude the content if path is a directory, but only directory itself.
I'm not sure how to interpret this.
Basically I have a directory which lives in /tmp
and which I don't want to be deleted (including its contents). For this, is it enough to add a line
x /tmp/myspecialdir
to /usr/lib/tmpfiles.d/tmp.conf
?
Best Answer
I also found this very confusing. Here's a quick example. I think x versus X becomes useful if you have a deep tree inside a particular directory and you want to delete some and not all directories.
Here's my exclude.conf:
root# cat /etc/tmpfiles.d/exclude.conf d /tmp/testdir 0755 root root 1s x /tmp/testdir/*
Now, I create some directories:
# 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
Run clean#systemd-tmpfiles --clean exclude.conf
Check
# 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
Now, if do
X /tmp/testdir/*
, I get the same result. Then, if I havex /tmp/testdir/b
, then it excludes the 'b' directory from the cleanup.#systemd-tmpfiles --clean exclude.conf
# ls -lrt /tmp/testdir/ total 0 drwxr-xr-x. 2 root root 6 Sep 1 12:55 b
Also,X /tmp/testdir/b
shows the same behavior. However,X /tmp/testdir/
andx /tmp/testdir
will delete all the sub directories insidetestdir
but will keeptestdir
.I would suggest to test the settings before you put it in place. I the man page could be little more clearer.