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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • 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. IBM DB2 Installation on Red Hat Enterprise Linux
  2. authconfig: command not found
  3. How to configure the logging of failed login attempts for vsftpd
  4. CentOS / RHEL 6 : How to completely remove device mapper multipath (dm-multipath)
  5. –force V/s –nodeps : rpm command options to install or uninstall a package
  6. nslookup: command not found
  7. CentOS / RHEL 5 : How to password-protect single user mode
  8. kscreen-console: command not found
  9. ifenslave Command Examples in Linux
  10. ps Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright