Loading...

Find and delete files older than x days

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

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 {} \;
Please remember the terms for blog comments.