Stop Ubuntu / Debian Linux From Deleting /tmp Files on Boot

by Vivek Gite on January 10, 2008 · 10 comments

Q. I know /tmp as it named is a temporary dircory, Debian policy is to clean /tmp at boot. However, I'd like to configure my Ubuntu Server to stop deleting files from /tmp on boot due to custom configuration issue. How do I configure behavior of boot scripts to stop deleting files on boot?

A. Users should not store files in /tmp, use /home or other partition, if you would like to keep the files. The behavior of boot scripts is controlled via a special configuration file called /etc/default/rcS. Open this file and modify TMPTIME variable.

On boot the files in /tmp will be deleted if their modification time is more than TMPTIME days ago. A value of 0 means that files are removed regardless of age. If you don't want the system to clean /tmp then set TMPTIME to a negative value(-1) or to the word infinite.

Configuration /etc/default/rcS

Open /etc/default/rcS file, enter:
$ sudo vi /etc/default/rcS
Set TMPTIME to 60 so that files in /tmp will deleted if their modification time is more than 60 days ago.
TMPTIME=60
Close and save the file. This configuration is used by /etc/init.d/bootclean script on boot to clean /tmp and other directories under all Debian based Linux distros.

A note about RHEL / CentOS / Fedora / Redhat Linux

Redhat and friends use /etc/cron.daily/tmpwatch cron job to clean files which haven’t been accessed for a period of time from /tmp. The default is 720 hours. If the file has not been accessed for 720 hours, the file is removed from /tmp. You can modify this script as per your requirements:
# cp /etc/cron.daily/tmpwatch /etc/cron.daily/tmpwatch.bak
# vi /etc/cron.daily/tmpwatch

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 10 comments… read them below or add one }

1 David January 11, 2008

Solaris puts /tmp into a memory-based filesystem; thus, when the contents of memory are lost, the contents of /tmp are lost.

If you want to keep /tmp under Solaris, you have to make a partition where it can be kept. Then adjust the file /etc/vfstab to the correct settings for /tmp.

However, I would strongly discourage using /tmp for something permanent; it can’t be that hard to move things to an appropriate place.

Reply

2 vivek January 12, 2008

Thanks for shading more light about Solaris UNIX.

Appreciate your post!

Reply

3 sl June 26, 2008

why delete files in tmp automatically?
my hard drive is more than 1000GB.

Reply

4 KermitTheFragger January 3, 2009

If you want to store temporary files that are not deleted at boot, why not use /var/tmp ? Thats what /var/tmp is for. See http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

Reply

5 lost6hrsofdownload November 1, 2009

Thanks for the post..im a novice user of *ux and i used to store files in /tmp on Redhat, so i didnt find a reason not to store em in ubuntu as well. i jus downloaded the alternate iso for karmic koala and stored it under /tmp, only to find it gone! :( => cant upgrade my ubuntu today!

Reply

6 biOos December 22, 2009

Thnks! very useful for ubuntu!!

Reply

7 Mukund June 25, 2010

Hi,

By mistake I have copied soem data in /tmp folder, after boot all data gone , is there any chance to recover my data. It would be gr8 if someone can help me with this.

Thanks
Mukund

Reply

8 Steve August 14, 2010

Thanks for this tip. In Ubuntu 10.04 (and possibly earlier releases),
the cleaning script is in /etc/init/mounted-tmp.conf.
— A Fedora user who just found out that Ubuntu is different … :-)

Reply

9 Bob January 19, 2011

Like someone mentioned for solaris above, many distributions mount /tmp to RAM-based storage (e.g. /dev/shm). So /tmp is wiped clean when you boot due to the nature of a RAM disk. There’s no way to recover the files. As others have mentioned, don’t store anything in /tmp that you aren’t willing to lose forever.

Reply

10 denpick June 2, 2011

Defending a bad and very tricky practice of a default to remove users files by saying what a user should or should not do is pretty arrogant. Who is anyone to tell me the user that my files are so unimportant that they will be deleted. It’s not the distro’s business. What a stupid decision…but what arrogance to defend it. No wonder Linux just can’t move from a geek OS. User’s hate this type of arrogance and trickery.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 4 + 14 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: