When does /tmp get cleared?

Posted May 25, 2015 11.2k views
System Tools

Do I need to enable it this way? I am running Centos 7

systemctl enable systemd-tmpfiles-clean.service

What would be the implications?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

systemd-tmpfiles-clean.service clears /tmp before shutdown. /tmp contains temporary files that some programs need, but do not expect them to be persisted across reboots.

In some cases, /tmp is mounted as a tmpfs filesystem which is stored entirely in RAM and is automatically cleared on reboot. However, that is not the case in the CentOS 7 image so you will need to enable systemd-tmpfiles-clean.service in order to have /tmp cleared on shutdown.

–clean: If this option is passed, all files and directories with an age parameter configured will be cleaned up.

May I know what is an ‘age parameter’?

How to enable systemd-tmpfiles-clean.service?

I run ‘systemctl enable systemd-tmpfiles-clean.service’ but with error:

The unit files have no [Install] section. They are not meant to be enabled
using systemctl…