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

    xiaoxiao2023-03-24  1

    文章参考 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/

     

    大小: 7.3 KB del_file_before_that_day.rar (866 Bytes)下载次数: 0 查看图片附件
    转载请注明原文地址: https://ju.6miu.com/read-1200170.html
    最新回复(0)