In Linux, we can use the find command to search the files across the file system. However, there might be a case when you must search the files modified before the x days. Then, you need to use the -mtime option and the find command to locate the files modified before x days.
You can use the number of days in two different formats -
+ with the number of days to search the file modified older than X days
– with the number of days to search the file modified within the last X days
Command to find the files that have been modified in the last X Days
Run the command below to find the files and directories modified in the last 25 days.
If you add a dot (.) in this command to search files in the current directory. Here, -mtime -25 means the files that have been modified in the last 25 days.
You can add a dot (.) in the command to search files in the current directory.
If you want to search the file in another directory then you have to specify the path for it. Here, -mtime -25 means the files that have been modified in the last 25 days.
You can change the number as per your requirement.
find . -mtime -25
You can also customize the search based on the file type. Use -type followed by -f (file) or -d (directory). The command given below will search for files only. If you want to customize your search and want to find the files only, then you can use the below-mentioned command –
find . -type f -mtime -25
Command to Find the Files Modified before X days
You can run the command to search the files and directories modified before 25 days. Add a dot (.) in this command to search files in the current directory. Here, -mtime +25 means files modified before 25 days. You can change the number as per your requirement.
find . -mtime +25
If you want to customize your search and find the files only, then you can use this command –
find . -type f -mtime +25