Monday, September 10, 2012

How to delete files not updated within X days

How to get a list of files which were not modified within last X days? Here is the trick. This command will print out information about those files which were not modified within last 30 days in the current directory:

find . -mtime +30 -type f -exec ls -la {} \; 


This command will delete those files which were not modified within last 30 days in the current directory:

find . -mtime +30 -type f -exec rm -fr {} \; 


No comments:

Post a Comment