This question already has an answer here:

On our webserver, we use /tmp to store a server-side cache. The cache path is unique for each website, and also for each git revision. So when the code is updated, the old cache folder is abandoned. The files therein are eventually deleted, but the folders themselves persist. This is not actually causing a problem (yet), but it seems messy. Is there any way to automatically delete folders in /tmp which have been empty for X days?

According to the man pages, tmpwatch should remove unused directories, but it is not doing so.

$ cat /etc/cron.daily/tmpwatch 
#! /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"

I see nothing there which would stop it removing directories.

However, ls -ul shows that all directories in /tmp (well, all that I checked) have been accessed today, even ones which shouldn't have been touched in months.

marked as duplicate by vonbrand, roaima, dhag, Ramesh, cuonglm Sep 8 '15 at 17:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • use: crontab. – Tejas Sep 8 '15 at 10:52

I believe the answer is given in When exactly does tmpwatch clear out files I place in /tmp? (I suppose that makes the question a duplicate but I cannot mark it as such).

  • 1
    from serverfault centos7 its configured in /usr/lib/tmpfiles.d/tmp.conf – gwillie Sep 8 '15 at 10:47

You can try adding option --dirmtime to the tpmwatch commands so that access time is not checked for directories, despite the -u. (changing flags='-umc --dirmtime' will not do as you also need to remove the double-quotes from "$flags").

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