RSS Feed

Find files that have been modified within or more than N days

Finding files that have been modified N+ days ago or less than N days is actually a common procedure for system administrators, but not only is it common, it’s dead easy.

Using the “-mtime” option you can find files based on their modified time, in days.

find /path/ -mtime +N


find /backups/sql -mtime +5

The above will find all files and directories that have a modified time that is greater or equal to 5 days ago.

Specifying “-type f” will limit the results to files only, “-type d” would limit the results to just directories.

find /backups/sql -type f -mtime +5

While the above example shows how to find files that were modified 5 or more days ago the following command will returns files that have been modified within the last 5 days.

fine /path/ -mtime -5

The only difference is the operand before the days. A plus represents “more than” and a minus represents “less than”.

If you happened to want to delete these files you can do so using the -exec option, like so:

find /backups/sql -type f -mtime +5 -exec rm {} \;

Other useful time options
-mmin N
Find files that were modified N minutes ago

-amin N
Find files that were accessed N minutes ago

-atime N
Files that were accessed N days ago

Finding files based on time is an easy task and often forgotten, however, when in doubt look at the manual for find.

man find

Nothing beats reading the manual, especially for a quick recap of how to “find” files.

Posted in Linux on the 26th May 2010


Your email address will not be published. Required fields are marked *