What mechanism controls how often/when the /tmp directory is cleaned up. If there is such built-in mechanism at all or do I need to resort to a custom cron?

I'd appreciate either a specific command/tool or if you just point me to where I can find the appropriate documentation.

I am using Ubuntu 10.04 server if it matters.


4 Answers 4


On Ubuntu, install tmpreaper.

apt-get install tmpreaper
  • Thank you. tmpreaper tool is exactly what I was looking for
    – Sergey G
    Sep 1, 2010 at 19:53

tmpwatch can be used to clean up /tmp.


Well, you can mount it in in swap/ramdisk (google for how to set that up) Solaris does this by default, cleans up with every reboot. :-) I've done it with Linux, it can be very nice, and makes /tmp nice and fast.

Personally, I would only delete stuff from /tmp that is older than the last reboot, or that I know is safe, lots of things have working data in /tmp, and it may we be from just after boot (I don't know that for sure, but I would be cautious, granted, worst case, reboot and you are fixed).


For long uptimes, tmpreaper is the way to go.

Ubuntu cleans /tmp at each boot. If you reboot, files may be deleted that you may have intended to keep based on thresholds supplied to tmpreaper. You can control boot-time /tmp cleaning using the TMPTIME variable.

From man rcS:

On boot the files in /tmp will be deleted if their modification time is more than TMPTIME days ago. A value of 0 means that files are removed regardless of age. If you don't want the system to clean /tmp then set TMPTIME to a negative value (e.g., -1) or to the word infinite.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .