I want to keep files newer than 7 days in /tmp between boots. Prior to 15.04 I did this by setting TMPTIME=7 in /etc/default/rcS. But with 15.04 and the replacement of upstart by systemd, this doesn't work. As far as I understand, the approach is through the file /usr/lib/tmpfiles.d/tmp.conf and the possibility of overriding it with /etc/tmpfiles.d/tmp.conf. But I have the default /usr/lib/tmpfiles.d/tmp.conf which has the line:

D /tmp 1777 root root -

The final - means, according to the tmpfiles.d man page, that no automatic cleanup is done. But, in fact my /tmp is cleaned out with every reboot and I could not find a way to stop that. Why is /tmp getting cleaned out, and how can I change that?

  • Just out of interest, why do you want to keep files in /tmp after reboots? – thomasrutter May 19 '15 at 3:31
  • 1
    I often download files or create scratch files that I may need for a day or two but don't want to keep permanently, so I have been keeping them in /tmp with a 7 day day clean out period. Its a workflow that has been effective for me for many years, and I would like to keep it up. The documentation seems to suggest that the tmpfiles.d system is designed to support this, but I can't get it to work. – dnarnold May 19 '15 at 23:38
  • For this I use a "Temp" directory in my home directory, eg ~/Temp as /tmp has a system specific purpose and I don't want to pollute the global /tmp. That said, good luck on solving your problem but I'm sorry I don't personally know how to solve it. – thomasrutter May 20 '15 at 0:25

I fixed this by creating the file /etc/tmpfiles.d/tmp.conf containing:

# Override cleaning of /tmp in vendor /usr/lib/tmpfiles.d/tmp.conf,
# as documented in tmpfiles.d(5), for Kubuntu 15.04 and above that
# use systemd.  First char is 'd', instead of 'D', to avoid cleaning.

d /tmp 1777 root root -
| improve this answer | |
  • /tmp to me is a sort of recycle bin which I want to clean by my personal preferences. It is a valuable space for script debugging and thus should have a more sophisticated clean mechanism than just removing things at reboot. Using /var/tmp for more persistent stuff means to apply a cleanup process to that dir too so I'd like to leave it in /tmp in the 1st place. – user333869 Oct 22 '18 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.