Delete Files Older Than x Days on Linux

Command Syntax

find /folder/files* -mtime +15 -exec rm {} \;

The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +15, it will find files older than 15 days. The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

Another way to do it is:

/bin/rm `find /var/tmp/stuff -mtime +15 -print`
Tagged