Temp files are cleaned in Ubuntu by systemd-tmpfiles
and the related service /lib/systemd/system/systemd-tmpfiles-clean.service
, and the configuration for said files can be configured inside /etc/tmpfiles.d/*.conf
(also see this answer).
To include the directory you describe, create a config file:
sudo touch /etc/tmpfiles.d/scratch-tmp.conf
And then include this content in it:
# Type Path Mode User Group Age Argument
e /scratch/tmp - - - 20m
The e
type defines that this is a "marked" directory that already exists, but should be cleaned. An age setting of 20m
will clean all files more than 20 minutes old (see explanation below).
If the type is d
, the directory will be created if it doesn't exist, and cleaned up on reboot and each day.
Be aware that the timer triggering the service (found at /lib/systemd/system/systemd-tmpfiles-clean.timer
) is set to run 15 minutes after boot, so you won't see the actual effects at reboot until after 15 minutes uptime.
Please see the manpage for tmpfiles.d
for more information.