4 down vote accepted |
This is the easy enough (although note, goes by a modification time and than 3 days ago since a creation time is onl Y available on certain filesystems with special tools): find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-delete
Remove the # before the once you be sure that it's finding the files you want to -delete remove. To has it run by Cron, I would probably just create an executable script (add a shebang-to the top line of the #!bin/sh fi Le and make executable chmod a+x with), then put the it in a appropriate cron directory like /etc/cron.daily or /etc/cron.weekly . Provided of course that's you does not need a more specific schedule and that these directories exist on your distro. UpdateAs noted below, the -delete option for find isn ' t very portable. A POSIX compatible approach would be: find /a/b/c/1 /a/b/c/2 -type f -mtime +3 #-exec rm {} +
Again Remove the When is sure you has the right # files. Update2To quote from Stéphane Chazelas comment below:
Note that there is -exec rm {} + race condition vulnerabilities which -delete (where available) doesn ' t has. So don ' t use it on directories that is writeable by others. Some finds also has a that -execdir mitigates against those vulnerabilities.
|
Link:http://unix.stackexchange.com/questions/136804/cron-job-to-delete-files-older-than-3-days
Linux Delete files older than 3 days