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.

I post tutorials very regularly on this site. You may want to consider subscribing to the RSS feed. Or if you'd prefer these tips sent to your inbox you can use Email Subscriptions.

Related Posts

Random Posts

Comments

6 Responses to “Changing The /tmp Cleanup Frequency”

  1. Chris Samuel on January 19th, 2008 3:54 am

    That’s great Christer, very handy to know!

  2. Hans on January 19th, 2008 7:41 am

    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. hvdb on January 19th, 2008 10:00 am

    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 on January 19th, 2008 3:45 pm

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

  5. Jonathan on January 20th, 2008 6:33 am

    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 on January 25th, 2008 1:10 am

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

Leave a Reply




    Subscribe to the RSS feed!


    subscribe to the ubuntu tutorials RSS feed

    Get Ubuntu!


    Obama '08


    Obama '08 - Change We Can Believe In

  • Blogroll

  • Ads by Google