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

Cpanel/Whm License $3/mo Plesk License $10/mo Cloudlinux License $5/mo

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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Related posts

Zuckerberg to Study Crypto in Quest to Fix Facebook


Zooko Wilcox Envisions ‘Ambitious’ Changes for Zcash Cryptocurrency


ZombieChain Comes Alive: Can Ethereum Sidechains Save the Dapps?


ZoKrates Seeks to Bring Best of Zcash to Ethereum with Devcon Debut


Zk-Starks? New Take on Zcash Tech Could Power Truly Private Blockchains


Zk-Snarks Everywhere: Ethereum Privacy Tech Hits Tipping Point


ZipZap to Offer Cash-for-Bitcoin Service at 28,000 UK Locations


ZipZap Resumes Cash-to-Bitcoin Services for UK Shoppers


ZipZap Raises $1.1 Million to Grow Global Bitcoin Payments Network


This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More