How is the
/tmp directory cleaned up? Is it automatic? If so, how frequently is it cleaned up?
The directory is cleared by default at every boot, because
Here you can change the time in the following file:
The cleaning of
The script does roughly the following: if a file in
The default value of
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.
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.
On one of our servers running Ubuntu, we have a script to remove files in /tmp and it runs nightly.
The script is:
Just save the contents above to a file chmod 775 the file and create a cron entry to run it. Since this is a web server we don't want to reboot it for obvious reasons.
protected by Community♦ Feb 11 at 14:09
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?