Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
There is no built-in mechanism. Have a look at this… – Iain Sep 1 '10 at 19:29
up vote 2 down vote accepted

On Ubuntu, install tmpreaper.

apt-get install tmpreaper
share|improve this answer
Thank you. tmpreaper tool is exactly what I was looking for – Sergey G Sep 1 '10 at 19:53

tmpwatch can be used to clean up /tmp.

share|improve this answer

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).

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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