Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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
/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"

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?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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.
share|improve this answer

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 systemd[1]: Starting Cleanup of Temporary Directories...
Mar 12 21:44:18 systemd[1]: Started Cleanup of Temporary Directories.

Where "Started Cleanup" actually means "Complete".

share|improve this answer
The tmpwatch has a nice ability of using fuser. Can the systemd version do that? –  CMCDragonkai Apr 29 at 2:40
@CMCDragonkai, On April 2015, Lennart Poettering (SystemD developper) said on systemd-devel mailing list : "we do not support this [..] iterating through /proc is simply too bad.[..] we might consider it [otherwise]" then he added "atime checks [..] should be fully sufficient. Do you have a case where they aren't?" –  Franklin Piat Apr 29 at 16:48
Yea I asked that question. –  CMCDragonkai Apr 29 at 23:37
@CMCDragonkai, I was quoting Lennart Poettering on the mailing list. Reply to him (on the list) ! –  Franklin Piat May 4 at 22:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.