Controlling clearance of /tmp on Linux systems

While some may view the behaviour in a less favourable, I always have liked the way that Linux can clear its /tmp directory every time the system is restarted. The setting for this is in /etc/default/rcS and the associated line looks something like:


The value of 0 means that the directory is flushed completely every time the system is restarted but there are other options. A setting of -1 makes the directory behave like any other one on the system where any file deletions are manual affairs. Using other positive integer values like 7 will specify the number of days that a file can stay in /tmp before it is removed.

What brought me to this topic was the observation that my main Linux Mint system was accumulating files in /tmp and the cause was the commenting out of the TMPTIME=0 line in /etc/default/rcS. This is not the case in Ubuntu and using that is how I got accustomed to automatic file removal from /tmp in the first place.

All of this discussion so far has pertained to PC’s where systems are turned off or restarted on a regular basis. Things are different for servers of course and I have seen tools like tmpreaper and tmpwatch being given a mention. As if to prove that there is more one way to do anything on Linux, shell scripting and cron remain and ever present fallback.

Leave a Reply