• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 6,7 : Why the files in /tmp directory gets deleted periodically

By admin

In CentOS/RHEL 7, tmpfiles.d cleans up /tmp or /var/tmp by removing unused files. This function was called “tmpwatch” in CentOS/RHEL 6 which is invoked by crond, however, it is now realized by timer of systemd on CentOS/RHEL 7.

The main purpose of the /tmp directory is to temporarily store files when installing an OS or software. If any files in the /tmp directory have not been accessed for a while, they will be automatically deleted from the system. Please find below the configuration responsible to delete the files in /tmp directory.

For CentOS/RHEL 6

1. A cronjob that is installed and started by the system by default, runs the command tmpwatch which scans all entires in /tmp every minute. The cronjob of tmpwatch is set in /etc/cron.daily/tmpwatch

# cat /etc/cron.daily/tmpwatch
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
	-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
	-X '/tmp/hsperfdata_*' -X '/tmp/.hdb*lock' -X '/tmp/.sapstartsrv*.log' \
	-X '/tmp/pymp-*' 10d /tmp

2. You can find more information on tmpwatch on its man page.

# man tmpwatch

For CentOS/RHEL 7

1. In case of CentOS/RHEL 7, systemd-tmpfiles cleans up files in /tmp directory periodically. The setting for cleaning up /tmp directory is in /usr/lib/tmpfiles.d/tmp.conf.

2. Below is the default configuration file – /usr/lib/tmpfiles.d/tmp.conf. As you can see the directories /tmp and /var/tmp are scheduled to be cleaned up every 10 and 30 days respectively.

# cat /usr/lib/tmpfiles.d/tmp.conf
# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp

3. More information about systemd-tmpfiles, please see the man pages:

# man systemd-tmpfiles
# man tmpfiles.d
How to disable auto deletion of the files in /tmp and /var/tmp directories in CentOS / RHEL 5,6
CentOS / RHEL 7 : how tmpfiles clean up /tmp/ or /var/tmp (replacement of tmpwatch)

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. “sudo: /etc/sudoers is world writable” – How to correct the permissions of sudoers file
  2. How to change the default location (/var/cache/yum) of yum cache
  3. Comparing NET-TOOLS V/s IPROUTE Package Commands (ip Vs ifconfig command comparison)
  4. How Files/Directories in /tmp gets Removed Automatically in CentOS/RHEL 5,6
  5. Status Commands in Linux – date, ps, who, uptime, finger, rup, ruser
  6. What are Reserved User Accounts in MySQL
  7. 5 Useful Command Examples to Monitor User Activity under Linux
  8. How to configure Linux Resource Groups (cgroups) for MySQL
  9. How to Configure Interface(s) in promiscuous mode on CentOS/RHEL 7 (persistently)
  10. Linux OS Service ‘sysstat’

You May Also Like

Primary Sidebar

Recent Posts

  • What are different Oracle Database Vault Roles
  • Unable to export realm protected table using data pump
  • Beginners Guide to Oracle Database Vault
  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary