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

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 16 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
16 comments… add one
  • David Jan 11, 2008 @ 21:30

    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.

  • 🐧 nixCraft Jan 12, 2008 @ 9:32

    Thanks for shading more light about Solaris UNIX.

    Appreciate your post!

  • sl Jun 26, 2008 @ 20:12

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

  • KermitTheFragger Jan 3, 2009 @ 12:18

    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

  • lost6hrsofdownload Nov 1, 2009 @ 13:28

    Thanks for the 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!

  • biOos Dec 22, 2009 @ 21:38

    Thnks! very useful for ubuntu!!

  • Mukund Jun 25, 2010 @ 7:02


    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.


  • Steve Aug 14, 2010 @ 14:03

    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 … :-)

  • Bob Jan 19, 2011 @ 13:51

    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.

  • denpick Jun 2, 2011 @ 13:34

    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.

    • TOMOTH Jul 25, 2013 @ 14:35


      Thank you, Thank you, THANK YOU!

      I am in 100% agreement with your comment.

      The only thing I would add is the arrogancy of turning on all sorts of packages that the average user doesn’t run – like a FINGER PRINT SCANNER!


  • Ethan Lamoureux Feb 19, 2012 @ 12:33

    I just looked up this info because of a situation I am in. I generate a lot of data on my computer, and if I forget to make backups and delete stuff regularly, my home partition can fill rapidly. Also my root partition is nearly full because of Ubuntu’s insanely small default root partition size. The only partition I have left for moving things around in order to make backups is my /tmp partition, and so I currently have important data stored there.

    It so happens that my DVD burner has decided to lock up on me, and the only way I can get it back is to reboot… but, you guessed it, if I reboot, MY IMPORTANT DATA will be LOST FOREVER because some IDIOT(S) decided to delete files there without asking me, the user, what I want. And then to top it off, we’re told that “there are better places to keep user data.” Right, like in one of my other partitions which are filled up?

    Please, if you write software, REMEMBER THE USER! And if you write advice for users, remember that not every user’s situation is ideal!

  • Sebastian Mar 6, 2012 @ 20:49

    /tmp is not supposed to be used as a storage. The user workspace is its /home/xyz directory, why does they expect data stored elsewhere to still be there at any other time?

    RL analogy: Put your TV set on the sidewalk (ie, outside your “home”) and see if it’s still there tomorrow. It might be, but you can’t be sure.

    • Ethan Lamoureux Mar 7, 2012 @ 6:05

      Bad analogy. The public sidewalk is public, with no security. My /tmp directory though is private, only those with access to my computer can do anything with it. Also, each user’s data is protected from being tampered with by other users, so there is a measure of security. Finally, I have no control over the public sidewalk, but I own my computer and its /tmp directory and should not have to tolerate undesired behavior.

      Did you not read my message illustrating why “Use your home directory!” is not always possible? Is not temporary persistent storage a legitimate use for a /tmp directory?

  • Nicola Manini Nov 12, 2012 @ 20:08

    The article is fine and provides a solution to Ethan’s problem.
    1) it is desirable to have a /tmp folder where to throw temporary files and not having to worry to clean them up later, so the default unix behavior is fine. I usually set TMPTIME=7: one week seems long enough for my own taste.
    2) the ramdisk /tmp is a crazy idea. Luckily present-day debian has given it up and by default /tmp is in the physical disk.
    3) Ethan’s example shows how bad an idea it is to multilply partitions: /tmp should be part of the / partition. It may occasionally make sense to have a separate /home partition, although it is often unnecessary. Personally I do create /home as a separate partition in desktop pcs with plenty of disk space, but would never have one in a laptop, where disk space may run out.

  • ask_for_more Dec 5, 2012 @ 10:54

    let’s say you want to cleanup your fish tank, so you have to put your fish somewhere temporarily. If you don’t find any better place than toilet sink, well let it be, but be so kind and place them back into the tank as after single flush your fish be gone :)

    same for /tmp directory – files are not supposed to be stored there.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum