Linux: Find and Delete Files with Modification Time Older Than 30 Days

In this tutorial, we will introduce how to delete files with modification time is older than 30 days in linux.

Linux: Find and Delete Files with Modification Time Older Than 30 Days

The delete command is:

find /path/to/ -type f -mtime +30 -name '*.log' -exec rm -f {} \;

You should notice:

find: find command is used to find files/directories/links and etc

/path/to/: the directory to start your search in

-type f: only find files

-name ‘*.log’: list files that ends with .log

-mtime +30: only consider the ones with modification time older than 30 days