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.
That’s great Christer, very handy to know!
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.
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?
Some people have /tmp on a tmpfs, which is in RAM and thus reset at reboot…
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 🙂
@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).
@Richard Ubuntu (default Feisty and Intrepid) has NOT a default /tmp as tmpfs so setting TMPTIME in /etc/default/rcS works.
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.
It seems that Unbutu 9.10 (/sbin/mountall) counts TMPTIME in hours instead of days.
@RobertH: What makes it seems like that (any source?)
@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.
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 🙁
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.
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/macromedia.com/support/flashplayer/sys/*. 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/macromedia.com/support/flashplayer/sys/*
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.