Home > Ubuntu > Changing The /tmp Cleanup Frequency

Changing The /tmp Cleanup Frequency

While the /tmp folder is not a place to store files long-term, occasionally you want to keep things a little longer than the next time you reboot, which is the default on Ubuntu systems. I know a time or two I’ve downloaded something to /tmp during testing, rebooted after making changes and then lost the original data again. This can be changed if you’d like to keep your /tmp files a little bit longer.  The default on Redhat systems, for example, is to keep files roughly ten-days.

Changing the /tmp Cleanup Frequency

The default setting that tells your system to clear /tmp at reboot is held in the /etc/default/rcS file. The value we’ll look at is TMPTIME.

The current value of TMPTIME=0 says delete files at reboot despite the age of the file. Changing this value to a different (positive) number will change the number of days a file can survive in /tmp.

TMPTIME=7

This setting would allow files to stay in /tmp until they are a week old, and then delete them on the next reboot. A negative number (TMPTIME=-1) tells the system to never delete anything in /tmp. This is probably not something you want, but is available.

I have been wondering how to do this on Ubuntu and finally found it today.  Enjoy.

If this article has been helpful, please consider linking to it.

Categories: Ubuntu Tags:

Related Posts

  1. January 19th, 2008 at 03:54 | #1

    That’s great Christer, very handy to know!

  2. Hans
    January 19th, 2008 at 07:41 | #2

    Interesting, but I think it’s the wrong approach. Technically, you’re not guaranteed that anything in /tmp will be there even 5 minutes from now, reboot or not. It just so happens that most linux distros only clean up /tmp on reboot, but other unices aren’t so predictable. /tmp is just a bad place to put things that you don’t want to lose yet, just like the trash is a bad place to put leftovers you may or may not want to eat tomorrow. I make a ~/tmp for that purpose. I should probably find another name for it, but I haven’t had any bursts of creativity on the subject yet.

  3. January 19th, 2008 at 10:00 | #3

    only every reboot?
    Isn’t there a cron of some sort which cleans the /tmp dir too?

    I’ve got my pc turned 24/7 or in suspend does that mean my tmp dir doesn’t get cleaned?

  4. Tormod
    January 19th, 2008 at 15:45 | #4

    Some people have /tmp on a tmpfs, which is in RAM and thus reset at reboot…

  5. January 20th, 2008 at 06:33 | #5

    I don’t reboot my laptop often, but when I do, /tmp might have become quite big. Not cleaning out /tmp on boot every time might actually improve boot-up times. I’ll see how it goes :)

  6. Richard
    January 25th, 2008 at 01:10 | #6

    @Tormod: you are right, and in fact Ubuntu’s default configuration is to put /tmp in a RAM based file system (tmpfs). So *anything* you put in /tmp will be automatically lost on reboot.

    To check this on your system, just type ‘mount’ or ‘df -hT’ (h for human units, T for show types).

  7. jancelis
    November 26th, 2008 at 05:42 | #7

    @Richard Ubuntu (default Feisty and Intrepid) has NOT a default /tmp as tmpfs so setting TMPTIME in /etc/default/rcS works.

  8. jeremy
    July 7th, 2009 at 16:41 | #8

    I know this is an old thread, and my question is not directly related, but some of you seem like experts on the tmp directory. There seems to be a bug in ubuntu with the tmp directory filling up and then certain programs, like Firefox, doing things like not letting you download anything or watch video.

    Here's a couple bug reports on it:
    https://bugs.launchpad.net/ubuntu/+source/sysvini...
    https://bugs.launchpad.net/ubuntu/+bug/285096

    I'm running Jaunty 9.04 64 bit, I've got a big harddrive (250g)+ with tons of free space, 4g RAM.

    I feel like this should be an easy fix, like setting some config setting to allow a bigger tmp directory. Thanks for any help.

  9. RobertH
    December 14th, 2009 at 12:34 | #9

    It seems that Unbutu 9.10 (/sbin/mountall) counts TMPTIME in hours instead of days.

  10. Jarl Friis
    February 12th, 2010 at 00:40 | #10

    @RobertH: What makes it seems like that (any source?)

  11. Jarl Friis
    February 12th, 2010 at 00:42 | #11

    @hvdb: I also believe there is a cron job, because even on servers (machines that rarely reboots), /tmp is cleaned up from time to time.

  12. Jarl Friis
    February 12th, 2010 at 00:57 | #12

    hvdb :
    only every reboot?
    Isn’t there a cron of some sort which cleans the /tmp dir too?
    I’ve got my pc turned 24/7 or in suspend does that mean my tmp dir doesn’t get cleaned?

    10Rate This

    PDRTJS_settings_1180493_comm_3476 = {
    “id” : “1180493″,
    “unique_id” : “wp-comment-3476″,
    “title” : “only+every+reboot%3F%0D%0AIsn%27t+there+a+cron+of+some+sort+which+cleans+the+%2Ftmp+dir+too%3F%0D%0A%0D%0AI%27ve+got+my+pc+turned+24%2F7+or+in+suspend+does+that+mean+my+tmp+dir+doesn%27t+get+cleaned%3F…”,
    “item_id” : “_comm_3476″,
    “permalink” : “http%3A%2F%2Fubuntu-tutorials.com%2F2008%2F01%2F19%2Fchanging-the-tmp-cleanup-frequency%2F%23comment-3476″
    }

    I think you are right on this, and that “… and then delete them on the next reboot. ” is incorrect, the cron job will delete it, but I am not sure. grepping recursively for ‘TMPTIME’ in /etc/* only gives /etc/default/rcS as a file :-(