Find Last 30 days modified files in Linux

Find Last 30 days modified files in Linux

Linux allows you to search for files across the system using the find command. But what about the cases when you need to find files that were modified in a certain time period? Linux has commands for that purpose as well. It is the -mtime option. It’s used together with the find command to search for files. In this article, learn how to use this option.

Finding Files Modified in the Last X Days

To search for the files that were modified in the last X days, you need to run the following command:

Code:
find . -mtime -X
Replace X with the number of days. So for files modified in the last 30 days, the command will look like this:

Code:
find . -mtime -30
The dot(.) signifies that you’re searching for files in the current directory. You can further customize the search by including -type parameter. So the command will look like this:

Code:
find . -type f -mtime -30
f after the -type means files. You can also use ‘d’ which would mean directory.

Finding Files Modified Before X Days

To look for files that were modified before a certain date, you need to replace – (minus) with + (plus) symbol. So the command to be executed will become:

Code:
find . -mtime +30
It will return files that were modified before 30 days. You can specify -type and d to look for directories instead.

So that’s how you find files that were modified in the last 30 days in Linux.
Author
kumkumsharma
Views
2,458
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top