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$ 

总结:
-mtime +1 表示超过2天(48小时)
-mtime +0.1 表示超过1.1天(26.4小时)
-mtime 1 表示超过1天,不到2天(超过24小时,且在48小时内)
-mtime 0.2 表示超过0.2天,不到1.2天(超过4.8小时,且在28.8小时内)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值