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:
Replace X with the number of days. So for files modified in the last 30 days, the command will look like this:
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:
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:
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.
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
Code:
find . -mtime -30
Code:
find . -type f -mtime -30
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
So that’s how you find files that were modified in the last 30 days in Linux.