linux下find命令-atime,-ctime,-mtime真正含义

系统 1772 0

文章参考 http://blog.itpub.net/26675752/viewspace-1058878/

 

一、概念说明

atime的意思是access time,即文件的最近的一次访问时间,+n意思为查找n天以前的文件,-n为查找n天以内的文件

 

mtime比较好理解,为modify time,即文件数据最新的修改时间,指的就是 文件内容的最新修改时间

 

ctime的意思是change time, 文件状态最新改变的时间 。是文件的status change time,何为文件的status呢?

我们都知道文件有一些个基本的属性,权限,用户,组,大小,修改时间等,只要是这些信息变化了,那么ctime都会发生变化,

所以上面修改文件内容时为何ctime会变化,因为其mtime已经变化了,mtime也是文件状态的一个。

 

 

二、例子

 

      #文件原始属性
[root@auc-test2 eccs]# stat eccs.log.20
  File: "eccs.log.20"
  Size: 10485916        Blocks: 20488      IO Block: 4096   普通文件
Device: fd02h/64770d    Inode: 1834242     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-12-17 02:43:15.901076752 +0800
Modify: 2014-12-17 02:43:15.914076752 +0800
Change: 2014-12-18 13:59:22.242796455 +0800

#修改访问时间属性(atime)
[root@auc-test2 eccs]# head -n 1 eccs.log.20
2014-12-17T00:51:53+08:00 [INFO] AstL
[root@auc-test2 eccs]# stat eccs.log.20
  File: "eccs.log.20"
  Size: 10485916        Blocks: 20488      IO Block: 4096   普通文件
Device: fd02h/64770d    Inode: 1834242     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-12-18 14:01:11.791796442 +0800
Modify: 2014-12-17 02:43:15.914076752 +0800
Change: 2014-12-18 13:59:22.242796455 +0800

#修改文件状态时间属性(ctime)
[root@auc-test2 eccs]# chmod 777 eccs.log.20
[root@auc-test2 eccs]# stat eccs.log.20
  File: "eccs.log.20"
  Size: 10485916        Blocks: 20488      IO Block: 4096   普通文件
Device: fd02h/64770d    Inode: 1834242     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-12-18 14:01:11.791796442 +0800
Modify: 2014-12-17 02:43:15.914076752 +0800
Change: 2014-12-18 14:01:35.286796424 +0800

#修改文件内容时间属性(mtime)
[root@auc-test2 eccs]# echo "huangbiao" >> eccs.log.20
[root@auc-test2 eccs]# stat eccs.log.20
  File: "eccs.log.20"
  Size: 10485926        Blocks: 20488      IO Block: 4096   普通文件
Device: fd02h/64770d    Inode: 1834242     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-12-18 14:01:11.791796442 +0800
Modify: 2014-12-18 14:02:16.853796414 +0800
Change: 2014-12-18 14:02:16.853796414 +0800
    

 

 三 、显示说明

1、ls 命令显示的是 mtime时间

      [root@auc-test2 eccs]# stat eccs.log.20
  File: "eccs.log.20"
  Size: 10485926        Blocks: 20488      IO Block: 4096   普通文件
Device: fd02h/64770d    Inode: 1834242     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-12-18 14:01:11.791796442 +0800
Modify: 2014-12-18 14:02:16.853796414 +0800
Change: 2014-12-18 14:08:10.946796334 +0800
[root@auc-test2 eccs]# ll eccs.log.20
-rwxr-xr-x 1 root root 10485926 12月 18 14:02 eccs.log.20

    

 

 

2、sshd 连接显示的是mtime时间

 

 

四、根据制定日期删除文件的脚本

 附件del_file_before_that_day.rar 使用方法

      [root@auc-test2 log]# ./del_file_before_that_day.sh 2014-12-17
where do the files store?
/abc/efg/

    

 

linux下find命令-atime,-ctime,-mtime真正含义


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论