Changing The /tmp Cleanup Frequency

By | 2008/01/19

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.


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.

14 thoughts on “Changing The /tmp Cleanup Frequency

  1. Hans

    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.

  2. 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?

  3. Tormod

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

  4. Jonathan

    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 🙂

  5. Richard

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

  6. jancelis

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

  7. jeremy

    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:

    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.

  8. RobertH

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

  9. Jarl Friis

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

  10. Jarl Friis

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

  11. Jarl Friis

    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” : “”

    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 🙁

  12. boaz

    How would you react if you opened the tmp folder in ubuntu 8.04lts and there amognst
    some recent videos that you have opened and watched online( no download),you find
    gconfd , keyring , orbit ,seahorse ,tracker , pulse and virtual and if you delete everything you have terminated your logging possibilities and who knows what else.

  13. Andrew P.

    On a related note, the Adobe Flash plugin used by your browser has its own temporary files, called “Local Storage Objects”, or LSOs, which it keeps in its own directory. Unlike the /tmp directory in Ubuntu, Flash has no user-configurable mechanism for determining how often to purge this directory, but the clutter can easily be cleaned out with a shell script that is launched periodically as a cron job. On my system the files are located in ~/.macromedia/Flash_Player/#SharedObjects and ~/.macromedia/Flash_Player/*. The directories will normally contain collections of subdirectories and files, but the script only needs to clean them out completely with no regard to name. The Flash Player will recreate any folders it needs here the next time it runs. I’ve set mine up to be purged every time the system is started and every 12 hours thereafter.

    I use the following shell commands:

    rm -fr ~/.macromedia/Flash_Player/#SharedObjects/*
    rm -fr ~/.macromedia/Flash_Player/*

    I’ve also put a shortcut to my script in ~/.gnome2/nautilus-scripts so that it is easily accessible from the Nautilus file manager by right-clicking in a Nautilus pane. This allows me to clear the cache manually as desired.

Comments are closed.