• 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

How to disable auto deletion of the files in /tmp and /var/tmp directories 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 like /var/tmp. Cleaning up unaccessed files in /tmp is 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, a sample configuration file /etc/cron.daily/tmpwatch on CentOS/RHEL 5 looks like below:

# cat /etc/cron.daily/tmpwatch
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

The above configuration will remove files/directories that have not been accessed for 240 hours(10 days for /tmp) or 720 hours(30 days for /var/tmp).

A sample configuration file /etc/cron.daily/tmpwatch on CentOS/RHEL 6 looks like below:

# cat /etc/cron.daily/tmpwatch
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

The above configuration which will remove files/directories that have not been accessed for 10 (/tmp) or 30(/var/tmp) days.

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, you can use either of the methods described below.

Method 1 – Removing the tmpwatch package

Easiest way is to remove the tmpwatch package itself:

# rpm -e tmpwatch

or

# yum remove tmpwatch

Method 2 – Disable the tmpwatch cron entry

In some cases you may not be able to remove the tmpwatch package because of the dependencies it has. You would get an error shown 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

Alternatively, you can also move or remove /etc/cron.daily/tmpwatch file responsible to schedule the removal of file from /var/tmp and /tmp/directories.

# mv /etc/cron.daily/tmpwatch /other/location/tmpwatch.bkp

or

# rm /etc/cron.daily/tmpwatch

Filed Under: Linux

Some more articles you might also be interested in …

  1. pstree: command not found
  2. chromium-browser: command not found
  3. How to Map Static IP to your Domain (with GoDaddy example)
  4. LVM Configuration : Physical Volume (PV) Operations/Utilities
  5. CentOS / RHEL : How to find kernel parameters used while booting
  6. vmstat: command not found
  7. RHEL 7 – RHCSA Notes – input / output redirection
  8. How to use fdisk to partition a disk in Linux
  9. watch Command Examples in Linux
  10. atrm Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright