Cron Job to auto delete folder older than 7 days Linux
For example, the description of crontab for deleting files older than 7 days under the /path/to/backup/
every day at 4:02 AM is as follows.
02 4 * * * find /path/to/backup/* -mtime +7 -exec rm {} \;
Please make sure before executing rm
whether targets are intended files. You can check the targets by specifying -ls
as the argument of find
.
find /path/to/backup/* -mtime +7 -ls
mtime
means the last modification timestamp and the results of find may not be the expected file depending on the backup method.