Table of Contents

Tmpwatch

General Information

tmpwatch is a utility that recursively removes files that haven't been accessed for a specified period of time.

It is normally used to clean up directories such as /tmp.

Checklist


Install

Tmpwatch does not come installed on a CentOS 6 minimal installation.

yum install tmpwatch

cron.daily

After installation, there will now be a tmpwatch cron script in: /etc/cron.daily/tmpwatch

See examples below for contents and explanation.


Tmpwatch Usage

Format

tmpwatch -[options] <time> <directories>

time

directories

Common Options


Examples

Fictional App in /opt

tmpwatch -umc 30d /opt/app/tmp

Default /etc/cron.daily/tmpwatch

First tmpwatch (with all the “-x”)

Second tmpwatch “$flags” 30d /var/tmp

Third /usr/sbin/tmpwatch “$flags” -f 30d “$d”

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