Delete a file older than X days using mtime

List files older than 5 days:
find ./ -mtime +5

To count all files older than 5 days
find ./ -mtime +5 |wc -l

To move files to an archive directory:
find ./ -mtime +5 -exec mv {} /var/archive \; -print

To delete the files
find ./ -mtime +5 -exec rm {} \; -print

You can leave a response, or trackback from your own site.

Leave a Reply