心を空にしようとしています。なぜfind
ファイル変更時間を解釈する方法。特に-mtime +1
48時間を過ぎたファイルはなぜ表示されないのか理解できません。
サンプルテストで変更日が異なる3つのテストファイルを作成しました。
[root@foobox findtest]# ls -l
total 0
-rw-r--r-- 1 root root 0 Sep 25 08:44 foo1
-rw-r--r-- 1 root root 0 Sep 24 08:14 foo2
-rw-r--r-- 1 root root 0 Sep 23 08:14 foo3
その後、スイッチを使って find を実行し、次の-mtime +1
ような出力を得ました。
[root@foobox findtest]# find -mtime +1
./foo3
その後、findを実行して次の-mmin +1440
ような結果を得ました。
[root@foobox findtest]# find -mmin +1440
./foo3
./foo2
findのマニュアルページによると、これが予想される動作であることがわかります。
-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.
-atime n
File was last accessed n*24 hours ago. When find figures out
how many 24-hour periods ago the file was last accessed, any
fractional part is ignored, so to match -atime +1, a file has to
have been accessed at least two days ago.
しかし、それはまだ私には理解できません。それでは、ファイルが1日23時間59分59秒を過ぎた場合、find -mtime +1
その内容をすべて無視して1日0時間0分0秒になったものとして処理しますか?この場合、技術的には1日より古くないので無視されますか?
いいえ…いいえ…計算。
ベストアンサー1
のパラメータは-mtime
次のように解釈されます。一日中文書時代。-mtime +n
方法厳密に言えば、次より大きい、-mtime -n
方法厳しく未満。
Bashを使用すると、より直感的な操作を実行できます。
$ find . -mmin +$((60*24))
$ find . -mmin -$((60*24))
24時間より古いファイルと24時間より新しいファイルをそれぞれ見つけます。
-mtime
(時間または分単位で解析したい場合は、小数引数を入力するよりも簡単です。)