How tmp directory is cleaned

The /tmp directory in Linux is where temporary files and directories are created by applications. If you did not do anything special during installation, it will be a directory under the root directory partition and hence has the same filesystem as that of the root filesystem. If you specifically created a partition for /tmp, then it might be of the tmpfs filesystem type.

If the root partition is running out of space, you might want to check how big tmp directory is:

$ cd /tmp
$ du --summarize .

On my Ubuntu, I find that tmp directory is cleaned up only at the time of system startup or reboot. The init scripts in /etc/rcS.d check the TMPTIME value set in /etc/default/rcS. This value indicates which files and directories in the tmp directory are up for deletion.

You can change this TMPTIME value to your preference:

  • If TMPTIME=0, then everything inside the tmp directory is deleted at reboot.
  • If TMPTIME=1, then only files and directories older than a day are deleted and so on.
  • If TMPTIME=-1, then nothing is deleted.

You will notice that the tmp directory is cleaned up only when you reboot the system. If you want a periodic cleanup of the tmp directory, then use the tmpreaper tool as described here.

Tried with: Ubuntu 14.04

Advertisements

3 thoughts on “How tmp directory is cleaned

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s