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
CentOS / RHEL 7 : how tmpfiles clean up /tmp/ or /var/tmp (replacement of tmpwatch)