• 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. How to Run DNS and FTP services in a chroot Jail
  2. df: command not found
  3. How to Disable Docker Process and docker0 Interface on CentOS/RHEL
  4. notify-send: command not found
  5. startx Command Examples in Linux
  6. ports Command Examples in Linux
  7. “Failed to Start Activation of LVM2 Logical Volumes” and “Unit lvm2-activation-net.service Entered Failed State” – CentOS/RHEL 7 booting issue
  8. cpufreq-info: command not found
  9. kpartx: command not found
  10. CentOS / RHEL 7 : How to boot into emergency or multi-user mode from GRUB2

You May Also Like

Primary Sidebar

Recent Posts

  • batch: Execute commands at a later time when the system load levels permit
  • bat: Print and concatenate files
  • bastet: Clone of the game Tetris in the terminal
  • bashmarks: Save and jump to commonly used directories using 1 character commands

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright