How to delete files over x days old in *nix

If you have a server with an automated backup system, and you want backups over x days old to be deleted, this is the way you would do it. I use the command in a shell script that is executed every night at midnight – after the backup has been made.

rm {} ; executes the removal of the files. There is a space inbetween the brackets and the backslash.

Here is the command (My shell script runs as root when this is done):

find /foo/bar/* -mtime +15 -exec rm {} ;

Comments are closed.

Post Navigation