Delete all files older than X days

bashcronrmshell

So I have a cron setup to make backups of a folder into a tarball every hour. I would like to add into the shell script that I'm using the ability to have files deleted automagically after about three days, so that I don't have a crap ton of files.

How can I go about this? Thanks.

Best Answer

Add this line to the script (modify accordingly):

find /path/to/backup_folder -mtime +3 -exec rm {} \;

This assumes your backup tarballs and only your backup tarballs reside in that folder. You could also use the tmpwatch utility:

tmpwatch -mf /path/to/backup_folder 72
Related Question