#! /bin/csh -f /bin/ls . | perl -nle 'if (/\./) { $n++; if (-M $_ < 0.6) { $n= 0; exit;};}' \ -e '} END { print $n ' exit Returning 0 means no "clean" will be done in dir [pickup]; returning >=1 means it will be done. The nmb. actually means the nmb of files to be deleted (moved to trash). Only consider files not starting 'dot': ls does this. Only consider files with a dot in the name (i.e. an extension such as .ppt): If-condition does that. But if one of these has a recent date, then definitely return 0: -M does this; exit goes via the END box, so zero $n first. Currently set to 0.6 ==~ 14 hours. perl -M returns file's mod. date, scaled to be in terms of days e.g. 1.53967 /bin/ls . | grep '\.' | wc | perl -p -e 's/^\s*//; s/ .*$//' That was old impl.: no test for recent file, which led to auto-delete of a file after I put it there but before going to lecture.