Linux /tmp directory deletion

This page discusses deletion of age-expired files from the /tmp directory in Enterprise Linux 6.

The default /tmp deletion job is /etc/cron.daily/tmpwatch which contains the following:

#! /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_*' 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

In the above script the first call to /usr/sbin/tmpwatch deletes all files from /tmp that are more than 10 days old, with the exception of files in directories specified by the -x (exclude) parameter.

Scripts in /etc/cron.daily are executed by anacron which executes commands periodically with a frequency specified in days. Unlike cron, anacron does not assume that the server is running continuously.

Anacron is configured in /etc/anacrontab. By default /etc/anacrontab contains the following:

[root@vm19 cron.daily]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22

#period in days   delay in minutes   job-identifier   command
1       5       cron.daily              nice run-parts /etc/cron.daily
7       25      cron.weekly             nice run-parts /etc/cron.weekly
@monthly 45     cron.monthly            nice run-parts /etc/cron.monthly

Anacron stores its timestamp files in /var/spool/anacron. There are three timestamps representing the last day, week and month that the respective scripts were executed:

[root@vm19]# cd /var/spool/anacron

[root@vm19]# ls -l
total 12
-rw-------. 1 root root 9 Jun 15 03:39 cron.daily
-rw-------. 1 root root 9 May 23 12:15 cron.monthly
-rw-------. 1 root root 9 Jun 14 10:48 cron.weekly

[root@vm19]# cat cron.daily
20150615

[root@vm19]# cat cron.weekly
20150614

[root@vm19]# cat cron.monthly
20150523