I've been going to great lengths lately to solve similar issues on servers under my purview.
The simple answer is basically just: systemd-tmpfiles --clean
is a hot mess and you should look into alternatives
The less simple answer is a bit long.
systemd-tmpfiles
performs a variety of tasks, but its main one is unrelated to the --clean
option: ensuring that the state of your system is appropriately 'reset' upon reboots. That is to say, it ensures that directories and files which need to exist for various reasons are created, and ones which should not exist are removed (along with a long list of relatively esoteric things like creating filesystem subvolumes and quotas, block devices, etc., changing permissions, SELinux attributes, etc. See the manpage if you're curious about everything). These tasks are performed by systemd-tmpfiles --create
(for most things) and systemd-tmpfiles --remove
(for removing files and directories). These two subcommands consider, roughly, the start of each configuration line: the first field is the type of action, the second the target, the third the mode, etc. Generally, something like systemd-tmpfiles --create --remove
is run shortly after boot of the system, before anything that might depend on the actions it takes. One important thing to note is that these actions don't ever look at the fifth argument, the Age parameter. That's where --clean
comes in.
systemd-tmpfiles --clean
essentially piggybacks on top of this infrastructure by way of a single added field: the Age field. It only considers a few of the particular types of actions the other subcommands do, though: d, D, v, q, Q, C
, and also x
and X
(which only exist to exclude specific things from its cleanup). The ones of these that are relevant to normal use cases are just d
and D
, though, used for directories, creating-if-doesn't-exist and creating-if-doesn't-exist-or-emptying-if-it-does, respectively. With the ages marked, systemd-tmpfiles --clean
will remove the listed path when the age is older than configured.
Here's the catch: it really means the listed path only - the age marking is not recursively applied to the contents of the folder. This means that the configuration lines in your question will only ever remove the entirety of /tmp
or /var/tmp
, and only if nothing has happened within them for 10 or 30 days, respectively. To make things worse, none of the things which affect the age support globs except for x
and X
, which are for excluding things from cleanup.
The tmpfiles.d
manpage does list one interesting thing which may work for your case if you're lucky: "If the age field starts with a tilde character "~", the clean-up is only applied to files and directories one level inside the directory specified, but not the files and directories immediately inside it." -- for my case, the cleanup needed to happen two levels below /tmp
, so there was no way to use this to good effect.
Look into other solutions for cleaning up the contents of your /tmp
directory which consider it their primary purpose, rather than being tacked-on the end like systemd-tmpfiles --clean
is.
systemd
tmpfile. Not everything in /tmp is, any application can create files in/tmp
/tmp
directory. E.g., if I write an application that writes to/tmp
, should the tempfiles daemon delete it regardless of who created it?e
flag.age-by
option inAge
: unix.stackexchange.com/a/782467/78336