When exactly does tmpwatch clear out files I place in /tmp?

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.

On RHEL7/CENTOS7, there's a systemd target that runs daily: systemd-tmpfiles-clean.timer (to replace /etc/cron.daily/tmpwatch). The default values are both OnBootSec=15min and OnUnitActiveSec=1d. Quoting systemd.timer manpage:

OnBootSec= defines a timer relative to when the machine was booted up.

OnUnitActiveSec= defines a timer relative to when the unit the timer is activating was last activated.

So the /tmp is now cleaned daily, roughly at the hour when system boot: so the time is undefined. For large deployments, not all virtual machines perform the cleanup simultaneously, nice.

For history, run:

$ journalctl  -u systemd-tmpfiles-clean
Mar 12 21:44:17 c7.klabs.be systemd[1]: Starting Cleanup of Temporary Directories...
Mar 12 21:44:18 c7.klabs.be systemd[1]: Started Cleanup of Temporary Directories.

Where "Started Cleanup" actually means "Complete".

Tags:

Centos

Tmp