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

The Geek Diary

HowTos | Basics | Concepts

  • Solaris
    • Solaris 11
    • SVM
    • ZFS
    • Zones
    • LDOMs
    • Hardware
  • Linux
    • CentOS/RHEL 7
    • RHCSA notes
    • SuSE Linux Enterprise
    • Linux Services
  • VCS
    • VxVM
  • Interview Questions
  • oracle
    • ASM
    • mysql
    • RAC
    • oracle 12c
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Hadoop
    • Hortonworks HDP
      • HDPCA
    • Cloudera
      • CCA 131

How Files/Directories in /tmp gets Removed Automatically in CentOS/RHEL 5,6

By admin

If files/directories in /tmp have not been accessed for a long time, they may be removed automatically. “tmpwatch” cleans up the contents of /tmp or other temporary directories.

In most cases, tmpwatch removing files is safely ignorable as unused files should be removed from /tmp to free up file system space so the file system containing /tmp doesn’t fill over time.

However, if you strongly need to disable this function for some reason, despite the importance of tmpwatch in ensuring /tmp doesn’t cause a file system to fill, it is possible by uninstalling tmpwatch:

# rpm -e tmpwatch

or, alternatively, move/remove /etc/cron.daily/tmpwatch file in case the rpm package for tmpwatch can’t be removed, such as below:

# rpm -e tmpwatch
LANG=C rpm -e tmpwatch
error: Failed dependencies:
tmpwatch is needed by (installed) tetex-3.0-33.15.el5_8.1.x86_64
tmpwatch is needed by (installed) cups-1.3.7-32.el5_11.x86_64
#

Cleaning up un-accessed files in /tmp s a default function of package “tmpwatch”, which provides a cron job /etc/cron.daily/tmpwatch. This is a shell script kicked by crond daily, which checks /tmp, /var/tmp and several directories in /var/ and remove files/directories which have not been accessed for a long time.

For example, /etc/cron.daily/tmpwatch on CentOS/RHEL 5 shows:

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_*' 240 /tmp
/usr/sbin/tmpwatch "$flags" 720 /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
     if [ -d "$d" ]; then
        /usr/sbin/tmpwatch "$flags" -f 720 "$d"
     fi
done

which will remove files/directories that have not been accessed for 240 or 720 hours(=10 or 30 days).

/etc/cron.daily/tmpwatch on CentOS/RHEL 6 shows:

#! /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
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
     if [ -d "$d" ]; then
         /usr/sbin/tmpwatch "$flags" -f 30d "$d"
     fi
done

which will remove files/directories that have not been accessed for 10 or 30 days.

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : Resize (extend) non-root EXT3/4 filesystem on non-LVM device (hard disk partition)
  2. How to Transfer a File In Passive Mode by FTP
  3. How to manage File and Directory Permissions/Ownerships in Linux
  4. RPM : package installation Error : cpio: read failed
  5. How to use auditd to monitor a specific SYSCALL
  6. How to disable firewalld and and switch to iptables in CentOS / RHEL 7
  7. How to Configure Separate Port For SSH and SFTP On CentOS/RHEL
  8. CentOS / RHEL : Begginners guide to cron
  9. XFS error: Unable to mount filesystem With Noacl Permission in CentOS/RHEL 7
  10. Audit rules to log reboot command executions in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • How to Pause and Resume Docker Containers
  • How to find docker storage device and its size (device mapper storage driver)
  • Understanding “docker stats” Command Output
  • ‘docker images’ command error – “Permission Denied”
  • Docker Basics – Expose ports, port binding and docker link
  • Archives
  • Contact Us
  • Copyright

© 2019 · The Geek Diary