linux下文件的mtime

利用find命令按文件修改时间对文件进行清理时,预想中应该被清理的文件没有被清理掉,所以专门测试了下mtime的使用规则。

测试时间为:

wang:~/wmy/test$ date
2020年 10月 24日 星期六 17:55:50 CST
wang:~/wmy/test$ 

通过touch -mt 2010220800 20201022080000.txt 命令可以修改文件的最后修改时间,测试文件如下:

wang:~/wmy/test$ ll
总用量 8
drwxrwxr-x  2 senter senter 4096 10月 24 17:58 ./
drwxrwxrwx 21 senter senter 4096 10月 24 17:50 ../
-rw-rw-r--  1 senter senter    0 10月 22 04:00 20201022040000.txt
-rw-rw-r--  1 senter senter    0 10月 22 08:00 20201022080000.txt
-rw-rw-r--  1 senter senter    0 10月 23 00:00 20201023000000.txt
-rw-rw-r--  1 senter senter    0 10月 23 04:00 20201023040000.txt
-rw-rw-r--  1 senter senter    0 10月 23 08:00 20201023080000.txt
-rw-rw-r--  1 senter senter    0 10月 23 10:00 20201023100000.txt
-rw-rw-r--  1 senter senter    0 10月 23 12:00 20201023120000.txt
-rw-rw-r--  1 senter senter    0 10月 23 16:00 20201023160000.txt
-rw-rw-r--  1 senter senter    0 10月 23 20:00 20201023200000.txt
-rw-rw-r--  1 senter senter    0 10月 24 00:00 20201024000000.txt
-rw-rw-r--  1 senter senter    0 10月 24 10:00 20201024100000.txt
wang:~/wmy/test$ 

为方便查看文件的最后修改时间,上面列出的文件,文件名中包含文件的最后修改时间。

  1. 查找最后修改时间为24至48小时之间的文件
wang:~/wmy/test$ find -type f -mtime 1
./20201023120000.txt
./20201023040000.txt
./20201023100000.txt
./20201023000000.txt
./20201023080000.txt
./20201023160000.txt
wang:~/wmy/test$ 

20201023200000.txt、20201024000000.txt修改时间在24小时之内,
20201022040000.txt、20201022080000.txt修改时间超过48小时,find命令未搜索到这几个文件

  1. 修改时间超过1.1、1.5天的文件
wang:~/wmy/test$ find -type f -mtime +0.1
./20201023120000.txt
./20201022080000.txt
./20201023040000.txt
./20201022040000.txt
./20201023100000.txt
./20201023000000.txt
./20201023080000.txt
wang:~/wmy/test$ 
wang:~/wmy/test$ find -type f -mtime +0.5
./20201022080000.txt
./20201023040000.txt
./20201022040000.txt
./20201023000000.txt
wang:~/wmy/test$ 

上面一条命令,20201023160000.txt、20201024000000.txt等几个文件,修改时间在1.1天内,find命令未搜索到这几个文件
下面一条命令,20201023080000.txt及以后修改的文件,修改时间在1.5天内,find命令未搜索到这几个文件

  1. 修改时间超过48小时的文件(22日18点之前)
wang:~/wmy/test$ find -type f -mtime +1
./20201022080000.txt
./20201022040000.txt
wang:~/wmy/test$ 

猜你喜欢

转载自blog.csdn.net/weixin_46381158/article/details/109263781
今日推荐