通過man手冊查找和-mtime選項相關的內容
man find | grep -A 3 mtime
# 這里簡單介紹了 -mtime ,還有一個簡單的示例
-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
文件數據最后一次修改是在 n*24 小時前。 請參閱 -atime 的注釋以了解舍入如何影響文件修改時間的解釋。find $HOME -mtime 0
Search for files in your home directory which have been modified in the last twenty-four hours. This command works this way because the time since each file was last modified is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.
在您的主目錄中搜索過去二十四小時內修改過的文件。 此命令以這種方式工作,因為自上次修改每個文件以來的時間除以 24 小時,并丟棄任何余數。 這意味著要匹配 -mtime 0,文件必須在過去(不到 24 小時前)進行修改。
這個示例說人話就是查找當前用戶的主目錄下在今天內被修改的文件。
例如今天是2023年12月8日 23點48分
-
-mtime 0
: 用于指定查找文件的修改時間。0
表示“今天之內”。今天凌晨(2023年12月8日 0點0分)過了0點到現在的時間段(2023年12月8日 23點48分) -
-mtime 1
:這里1就表示往前推1天,那就是昨天凌晨(2023年12月7日 0點0分)過了0點到現在的時間段(2023年12月8日 23點48分),如果改成2就表示往前推2天,以此類推。
然后n
還可以在前面使用+
和-
-
-mtime -1
:這個是往前推一天,就是昨天(2023年12月7日 23點48分)到現在(2023年12月8日 23點48分)。 -
-mtime +1
:這個用來查找1天前的文件,就是昨天(2023年12月7日 23點48分)以及更加早的文件。 -
總結:
??這里的+1
和-1
修改成其他的數字,就往前推算日期即可。除了-mtime 0
(-mtime 1
)表示今天(昨天到現在)內(從凌晨 0 點開始到當前時間),其他的-mtime
帶+n
和-n
選項都可以理解為相對于當前時間的時間范圍,需要推到相應的時間點,其中-n
是n天到現在的,+n
是n天以及更加早的。