The “find” command is required to find and display the required files in the current directory. It has several flags or options using which the output can be filtered. One of those flags is mtime (modification time), which displays the modified files based on a specific argument (in numbers).
Today’s writing explains the working of the “find” command’s “mtime” flag and explores why it only returns files older than two days:
- Why Does find -mtime +1 Returns Files Older Than 2 Days?
- The +1 Argument of the -mtime Flag
- Examples of the find Command with -mtime Flag
- Display the Files Modified in the Last 1 Day
- Display the Files Modified in the Last 23:59 Hours
- Display the Files Modified in the Last 30 Days
Why Does Find -mtime +1 Only Returns Files Older Than 2 Days?
When used with the “-mtime +2” flag, the find command returns only the files modified two days ago. For example, suppose we view the files modified three days ago. In that case, we’d use “-mtime +3.” The command output shows the modified files whose modification time is over three days:
$ find . -mtime +3
For the “-mtime +1” flag, it should be understood that “+1” doesn’t specify an exact time which only displays files modified more than one day but less or more than two days.
The +1 Argument of the -mtime Flag
The “+1” argument specifies a range of time, not an exact time. Specifically, it identifies files whose modification time is more significant than one day ago but less or equal to two days ago. Therefore, running the command on a file modified 48 hours ago will not be included because it is one day old.
Examples of the find Command With the -mtime Flag
The following examples are about using the -mtime flag of the find command.
Example 1: Display the Files Modified in the Last 1 Day
To view the files modified in the current directory (use the cd command explained here to navigate through the directories) from the last 24 hours or one day, execute this command:
$ find . -mtime +1
The +1 argument of the -mtime flag displayed a long list of files modified in the last day but less or more than two days.
Example 2: Display the Files Modified in the Last 23:59 Hours
To view the files modified in the last 23:59 hours (less than the day), use this command:
$ find . -mtime 0
The “find” command, when used with “-mtime 0,” displayed all the files that were modified in the last 23:59 hours.
Example 3: Display the Files Modified in the Last 30 Days
To view a detailed summary of the modified files in the last thirty days, use this command:
$ find . -mtime 30
Using the “30” argument to the flag “-mtime,” the records of the files that were modified in the last 30 days are displayed.
Conclusion
The argument “+1” of the “-mtime” doesn’t specify an exact time which only displays files modified more than one day but less or more than two days. A few examples above show the working of the “find” command with the flag “-mtime.”
This guide has explained why find -mtime +1 only returns files older than two days.
Check our LinkedIn company page