Find and delete files older than x days

On Linux you have powerful options with the find command. This post demonstrates how to find files older than 14 days (2 weeks) and remove them. Of course you can choose the amount of days as you like.

We search files with the modification time. Display the files

find . -mtime +14 -exec echo {} \;

Remove the files (with force option, in case it is interactive and have to reply with y)

find . -mtime +14 -exec rm -f {} \;

Combined command with multiple portions of exec

find . -mtime +14 -exec echo {} \; -exec rm -f {} \;