CentOS Tmpwatch – When Does It Clear Files in /tmp

centostmp

CentOS 6.x

I'm confused on when exactly files I place in /tmp/ are deleted.

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

The section in line 5 that reads -X '/tmp/hsperfdata_*' 10d /tmp leads me to believe that files I place in /tmp/ will remain for 10 days (assuming they aren't locked during deletion of course or the directory is mounted on a tmpfs file system).

Is that correct?

Best Answer

On CentOS 6, it would seem that tmpwatch is basing it's decision to delete on when a file was last accessed (atime). If it's been 10 days (10d) or more then it will be deleted when tmpwatch runs.

From the tmpwatch man page:

    By  default,  tmpwatch  dates  files  by their atime (access time), not 
    their mtime (modification time). If files aren't being removed when 
    ls -l implies they should be, use ls -u to examine their atime to see if 
    that explains the problem.

Also from the man page:

    The time parameter defines the threshold for removing files.  If the
    file has not been accessed for time, the file is removed.  The time 
    argument is a number with an optional single-character suffix specifying 
    the units: m for minutes, h for hours, d for days.  If no  suffix  is 
    specified, time is in hours.
Related Question