linux 时间 find,linux find 时间time

与时间有关的选项,共有-atime,-ctime与-mtime【-atime表示的是访问时间;-ctime表示被改变文件状态的时间;-mtime表示被修改文件内容的时间】,以-mtime说明-m

与时间有关的选项,共有-atime,-ctime与-mtime【-atime表示的是访问时间;-ctime表示被改变文件状态的时间;-mtime表示被修改文件内容的时间】,以-mtime说明

-mtime n:n为数字,意思是在n天之前的【一天之内】被更改过内容的文件;

-mtime +n:列出在n天之前(不含n天本身)被更改过内容的文档名;

-mtime -n:列出在n天之内(含n天本身)被更改过内容的文档名;

注释:

一个临时文件目录/exp/temp/之前写好脚本每天晚上23:30 定时清理1天前的所有文件;

今天客户找我/exp/temp/目录存在2天前的文件!

难道 find /exp/temp/* -ctime  +1 -exec rm  -rf {} \; 命令是查找‘2天’前的文件?、

看看我们的环境吧~

[root@report2 ~]# date

Fri Jan 16 17:34:39 CST 2015

[root@report2 ~]#

查看文件信息

[root@report2 ~]# ll  /exp/temp/

drwxr-xr-x 3 root root  4096Jan 14 20:07BJ_UNIT_1421237222585

-rw-r--r-- 1 root root  3238 Jan 14 20:07 BJ_UNIT_1421237222585.zip

drwxr-xr-x 3 root root  4096Jan 14 20:08BJ_UNIT_1421237303193

-rw-r--r-- 1 root root  3520 Jan 14 20:08 BJ_UNIT_1421237303193.zip

drwxr-xr-x 3 root root  4096Jan 14 20:11HJ_UNIT_1421237501049

-rw-r--r-- 1 root root 45621 Jan 14 20:12 HJ_UNIT_1421237501049.zip

[root@report2 ~]#

***文件都是2015-01-14 20点零几生成的目录/文件,最大时间是2015-01-14 20:12,最小时间是2015-01-14 20:07

***我们来执行一下往常的清理命令  find /exp/temp/* -ctime  +1 -exec rm  -rf {} \;

***按理说应该将2015-01-16 17:34:39 - 24小时= 2015-01-15 17:34:39的文件全部清理才对。

[root@report2 ~]# find /exp/temp/* -ctime  +1 -exec rm  -rf {} \;  ##执行查找删除命令

[root@report2 ~]# ll  /exp/temp/                                                 ##查看清理情况

drwxr-xr-x 3 root root  4096 Jan 14 20:07 BJ_UNIT_1421237222585

-rw-r--r-- 1 root root  3238 Jan 14 20:07 BJ_UNIT_1421237222585.zip

drwxr-xr-x 3 root root  4096 Jan 14 20:08 BJ_UNIT_1421237303193

-rw-r--r-- 1 root root  3520 Jan 14 20:08 BJ_UNIT_1421237303193.zip

drwxr-xr-x 3 root root  4096 Jan 14 20:11 HJ_UNIT_1421237501049

-rw-r--r-- 1 root root 45621 Jan 14 20:12 HJ_UNIT_1421237501049.zip

[root@report2 temp]#

*** 发现文件并没有做清理,那么是为什么没有清理呢,命令有问题?

*** 测试下-ctime +值 在哪个范围值能查到什么时间的文件

[root@report2 ~]# date

Fri Jan 16 17:41:05 CST 2015

[root@report2 ~]#  find /exp/temp/* -ctime  +0.90## 0.90*24=21.6   小时 能查到2015-01-14 20:08的BJ_UNIT_1421237303193文件

/exp/temp/BJ_UNIT_1421237222585

/exp/temp/BJ_UNIT_1421237222585.zip

/exp/temp/BJ_UNIT_1421237303193

/exp/temp/BJ_UNIT_1421237303193.zip

[root@report2 ~]#

[root@report2 ~]# date

Fri Jan 16 17:41:31 CST 2015

[root@report2 ~]#  find /exp/temp/* -ctime  +0.89##0.89*24=21.36 小时 能查到2015-01-14 20:12的HJ_UNIT_1421237501049文件(最大文件为该文件)

/exp/temp/BJ_UNIT_1421237222585

/exp/temp/BJ_UNIT_1421237222585.zip

/exp/temp/BJ_UNIT_1421237303193

/exp/temp/BJ_UNIT_1421237303193.zip

/exp/temp/HJ_UNIT_1421237501049

/exp/temp/HJ_UNIT_1421237501049.zip

[root@report2 temp]#

分析:

测试结果:

17:41:05时,  find  /exp/temp/* -ctime  0.90 天前(21.6 小时 )  能查到2015-01-14 20:08的BJ_UNIT_1421237303193文件

17:41:31时,  find  /exp/temp/* -ctime  0.89 天前(21.36 小时 )能查到2015-01-14 20:12的HJ_UNIT_1421237501049文件

而具体当时时间 0.89和0.9天前分别应该是什么时间呢?

SQL>  select ((24*60)+(17*60+41) -(0.9*24*60))/60 from dual ;

((24*60)+(17*60+41)-(0.9*24*60))/60

-----------------------------------

20.0833333

SQL> select ((24*60)+(17*60+41.5) -(0.89*24*60))/60 from dual ;

((24*60)+(17*60+41.5)-(0.89*24*60))/60

--------------------------------------

20.3316667

SQL>

*** 从sql上能看出

*** 2015-01-16 17:41分时的0.89天前能查到2015-01-14 20:08前生产的文件【2015-01-14 20:08前包括BJ_UNIT_1421237222585/BJ_UNIT_1421237303193】

*** 2015-01-16 17:41分时的0.90天前能查到2015-01-14 20:33前生产的文件【2015-01-14 20:33前包括所有文件,所以把所有都显示出来了..】

*** 从0.89天前 能看出来(当时0.89天前)2015-01-15 20:08 -2015-01-14 20:08(系统0.89天前) 正好差1天

*** 那想删除一天前生成的文件应该改为find  /exp/temp/* -ctime  -0 -exec rm  -rf {} \; 其中 0=1-1

*** 而每天23:30执行 find 所谓的‘1天’前的文件进行删除,,实际却是1+1=2天前的才进行删除,也导致今天执行find ..rm 没有删除任何文件;

*** 至于为什么一直以来教材上对find /exp/temp/* -ctime  +1 命令解释是查找1天前生成的文件,而实际上除了我们生产环境AIX上其他所有环境都是今天测试的样子

*** 只能默默的觉得是Linux不是最官方的被改过了.. 大家也看看你们的crontal find .. -ctime的是否也也同样的问题!

*** 或许谁能给我解释这个情况..先表示感谢.!

本文出自 “mojo” 博客,谢绝转载!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值