Linux: find time algorithm of mtime

In unix or linux environment often used such wording find -mtime to find the file before a certain point in time , as to how to write find -mtime + N / -N / N , that it is not very clear, today, to find some look at data, painted this chart to understand and remember:

As can be seen from the figure,

Since the beginning of the current time point, + indicates left , the starting point of time and then to push earlier, may be referred to outside XX;

- indicates right, the counting time from the point of time to push back, may be referred to within XX;

Accordingly no plus and minus signs represent the N-th day after.

find . -mtime N


In fact you should be understood ..
N * 24
represents the outside +1 hour +24 1 24 * ..
+ 0 * 24 0 only represents than +24 hours
1 represents between 1 * 24 + 24-24 ..
0 represents 0 * 24 + 24-0 ..
-1 indicates 0 * 24 +24, even for the future time ...

remember that 0 is a natural number ....

 

Therefore:
We look at this example:
My current time at 22:31 on March 1st, 2011, I have the following documents:

E:\testpath>ls -l
total 0
-rwxrwxrwa   1 Administrator   None                  0 Feb 25 22:37 111.txt
-rwxrwxrwa   1 Administrator   None                  0 Feb 26 22:38 222.txt
-rwxrwxrwa   1 Administrator   None                  0 Feb 27 22:38 333.txt
-rwxrwxrwa   1 Administrator   None                  0 Feb 28 22:01 444.txt
-rwxrwxrwa   1 Administrator   None                  0 Feb 28 22:30 555.txt
-rwxrwxrwa   1 Administrator   None                  0 Mar  1 22:31 666.txt<--当前时间的文件
-rwxrwxrwa   1 Administrator   None                  0 Mar  2  2011 777.txt

E:\testpath>
E:\testpath>

-mtime +2

-mtime +2, represent other than two days, that is, begin to run from two days of the current time (2011-03-01 22:31) before, to an earlier time goes on. Therefore, the two days of the current time distance: 2011-02-27 22:31, in the previous document, will be elected.

E:\testpath>find ./ -mtime +2
./111.txt
./222.txt

-mtime +1

-mtime +1, represent other than one day, that is, from the current time from the date of the day before, to an earlier time goes on. So the file before 2011-02-28 22:31 belong to the result, the file does not belong to the result 2011-02-28 22:31:

E:\testpath>find ./ -mtime +1
./111.txt
./222.txt
./333.txt
./444.txt
./555.txt

-mtime 2, the current time from the second day of the file, the current time is 22:31 2011-03-01, 2011-02-27 push forward 22:31 on day 2, so as a point in time 24 hours within the time as 2011-02-2722: 31 to 22:31 2011-02-28, so the file within this time will be selected out:

E:\testpath>find ./ -mtime 2
./333.txt
./444.txt
./555.txt

1 -mtime, the current time from the file on Day 1, the current time 2011-03-01 22:31, 1 day pushed forward 2011-02-28 22:31, so as a point in time 24 hours within the time as 2011-02-2822: 31 to 22:31 2011-03-01, so the file within this time will be selected out:

E:\testpath>find ./ -mtime 1
./666.txt

-mtime -1 represents less than 1 day for 2011-02-28 22:31, right from the current transition time from one day:

E:\testpath>find ./ -mtime -1
./
./666.txt
./777.txt

-mtime -2 represents less than two days, starting from 22:31 to 2011-02-27 from the current time of two days, goes on the right:

E:\testpath>find ./ -mtime -2
./
./333.txt
./444.txt
./555.txt
./666.txt
./777.txt

Reference Links: https://oracleblog.org/study-note/how-to-calculate-find-mtime/

Guess you like

Origin blog.csdn.net/fly910905/article/details/90447621