Automatically delete all files inside a directory older than a set number of days on linux


Use the following command:

find /home/user/Backup -type f -ctime +10 -exec rm -rf {} +

where +10 is the number of days. Replace by another number to set this to the appropriate number of days for you.

To schedule this action and make it automatic, place the command on your crontab, like this:

0 5 * * 1 find /home/user/Backup -type f -ctime +10 -exec rm -rf {} +

This will delete all files on the /home/user/Backup folder that are older than 10 days at 5am every week.

Comments