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

3 thoughts on “How tmp directory is cleaned

    1. Marcel Paulo: Thanks for informing. I wrote about Ubuntu 14.04. Apparently, they have now changed the cleaning method in 17.10 to use systemd.


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.