In this article I will show example of cron job for Linux to delete files older than 10 days.
How to Edit Crontab file
To edit or create new crontab file, type the following command:
$ crontab -e
Cron Job To Delete Files Older Than X Days
In crontab editor type:
0 0 * * * /usr/bin/find /target_directory -name "*.txt" -type f -mtime +10 -exec rm -f {} \;
Change /target_directory and “*.txt” as you need.
Cron expression 0 0 * * * means cron job will run every day at 12:00 AM.
You can read more about cronjob.
Discuss article in ArsTech Forum
Delete Files Older Than 7 Days
Start the discussion at forum.arstech.net