Linux 命令 find / -ctime +1 真的是查找1天前创建的文件咩?

简介:

标题: Linux 命令 find / -ctime +1 真的是查找1天前创建的文件咩?

作者: lōττéry ©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]



注释:
   一个临时文件目录/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  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 ~]#
 
 ***文件都是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的是否也也同样的问题!
 *** 或许谁能给我解释这个情况..先表示感谢.!



【源于本人笔记】 若有书写错误,表达错误,请指正...
目录
相关文章
|
8天前
|
NoSQL Linux Shell
常用的 Linux 命令
常用的 Linux 命令
30 9
|
1天前
|
安全 Linux 开发工具
Linux中可引起文件时间戳改变的相关命令
【4月更文挑战第12天】Linux中可引起文件时间戳改变的相关命令
9 0
|
3天前
|
域名解析 网络协议 Linux
Linux 中的 Nslookup 命令怎么使用?
【4月更文挑战第12天】
22 6
Linux 中的 Nslookup 命令怎么使用?
|
3天前
|
Linux Shell 开发工具
Linux文件常用操作
Linux文件常用操作(几乎覆盖所有日常使用)
58 0
|
3天前
|
运维 网络协议 Unix
18.系统知识-Linux常用命令
18.系统知识-Linux常用命令
|
4天前
|
网络协议 Ubuntu Linux
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
|
4天前
|
Linux Go
Linux命令Top 100驱动人生! 面试必备
探索Linux命令不再迷茫!本文分10部分详解20个基础命令,带你由浅入深掌握文件、目录管理和文本处理。 [1]: <https://cloud.tencent.com/developer/article/2396114> [2]: <https://pan.quark.cn/s/865a0bbd5720> [3]: <https://yv4kfv1n3j.feishu.cn/docx/MRyxdaqz8ow5RjxyL1ucrvOYnnH>
48 0
|
4天前
|
Linux 内存技术 Perl
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
【ZYNQ】制作从 QSPI Flash 启动 Linux 的启动文件
|
7天前
|
Linux
Linux 指令|date|cal|find|grep|热键
Linux 指令|date|cal|find|grep|热键
|
7天前
|
缓存 运维 监控
Linux系统监控利器:探索常用命令及数据保存技巧
Linux系统监控利器:探索常用命令及数据保存技巧
26 4
Linux系统监控利器:探索常用命令及数据保存技巧