31 Dec 2014
先提前看一下三个实验文件的日期,及分析它们之间的关系
ls -l total 8 drwxr-xr-x 3 root root 4096 Dec 25 17:44 shell -rw-r--r-- 1 root root 30 Dec 27 16:46 test.sed -rw-r--r-- 1 root root 0 Dec 31 22:59 today
<---------------------------------------------------------->
| | | | | | |
25 26 27 28 29 30 now #每个刻度都是当日的23:00
⑥ ⑤ ④ ③ ② ① now
先理论分析
验证n的含义
find . -maxdepth 1 -mtime 4 ./test.sed
n=4,但显示的结果是4-5之间,所以说明”n”显示的是第n+1天内修改的文件
find . -maxdepth 1 -mtime -4 . ./today find . -maxdepth 1 -mtime -5 . ./test.sed ./today
-n为-4时,显示的结果中没有了4-5之间的test.sed,但当-n为-5时显示有了test.sed,所以说明”-n”显示的是n天以内修改的文件,包括第n天
find . -maxdepth 1 -mtime +4 ./shell find . -maxdepth 1 -mtime +3 ./test.sed ./shell
+n为+3时,显示了shell与test.sed文件,但n为4时只显示了shell文件,所以说明”+n”显示的是第n+1天之前修改的文件,并不包括第n+1天
-mtime n :n为数字,意为查询第n+1天当天24小时内改动过内容的文件;-mtime +n :意为查询 n+1天之前(不含n+1天本身)被改动过內容的文件;-mtime -n :列出在 n 天之內(含 n 天本身)被改动过内容的文件;-newer file :file 为一个已存文件,列出比 file被改动内容更早之前的文件。例如,当n=4的时候 -mtime 4 是查询第5天改动过内容的文件; -mtime +4 是查询5天前改动过内容的文件; -mtime -4 是查询4天内改动过内容的文件。
4
<----->
-4<----------------------->
<----------------------------------|+4
<----------------------|-----|-----|-----|-----|-----|-----|-----|
7 6 5 4 3 2 1 现在