linux_wiki:tmpwatch

This is an old revision of the document!


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

  • Distro: Enterprise Linux 6

Install

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

yum install tmpwatch

After installation, there will now be a tmpwatch cron script in:

/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

Tmpwatch Usage

Format

tmpwatch -[options] <time> <directories>

time

  • Threshold for removing files.
  • Number with optional single character suffix
    • m = minutes
    • h = hours (default if not specified)
    • d = days

directories

  • One or more directories specified for clean up. (Space separated)

Common Options

  • -u, –atime ⇒ Delete files based on the file's access time. (default setting)
    • Note: the “updatedb” file system scans keep the atime of directories recent.
  • -m, –mtime ⇒ Delete files based on the file's modification time.
  • -c, –ctime ⇒ Delete files based on the file's inode change time. For directories, delete based on modification time.
  • -a, –all ⇒ Remove all file types, not just regular files, symbolic links and directories.
  • -f, –force ⇒ Remove files even if root doesn't have write. (same as rm -f)
  • -t, –test ⇒ Don't actually remove anything.
  • -v, –verbose ⇒ Print display.
  • -x ⇒ Skip specified path. (if directory, skip all files inside)
  • -X ⇒ Skip paths matching specified pattern.
  • Clean up an application's tmp directory at /opt/app/tmp
  • Check access time (-u), modification time (-m), and change time (-c).
  • Delete if any of the three are older than 30 days.
tmpwatch -umc 30d /opt/app/tmp

  • linux_wiki/tmpwatch.1444964332.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)