Linux精讲——atime、mtime、ctime

概念

通过 stat filename 命令查看一个文件的三个时间属性

[root@centos01 ~]# stat 1.txt
  File: `1.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 931337      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-02-27 22:20:10.803907698 +0800
Modify: 2016-02-27 22:20:10.803907698 +0800
Change: 2016-02-27 22:20:10.803907698 +0800

Access 后面的时间即为atime,文件被读会更改此属性
Modify 后面的时间即为mtime,文件内容改变会更改此属性
Change 后面的时间即为ctime,inode信息改变会更改此属性

如何更改atime、mtime、ctime

如上,1.txt 是新建的一个文件,初始状态其三个时间都一样的

  • cat 1.txt 后,atime 改变,mtime 和 ctime 不变
[root@centos01 ~]# cat 1.txt
[root@centos01 ~]# stat 1.txt
  File: `1.txt'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 931337      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-02-27 22:24:24.653927639 +0800
Modify: 2016-02-27 22:20:10.803907698 +0800
Change: 2016-02-27 22:20:10.803907698 +0800
  • echo "123" >> 1.txt 后,mtime 改变,ctime 改变,atime 不变
[root@centos01 ~]# echo "123" >> 1.txt
[root@centos01 ~]# stat 1.txt
  File: `1.txt'
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 931337      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-02-27 22:24:24.653927639 +0800
Modify: 2016-02-27 22:29:36.153926096 +0800
Change: 2016-02-27 22:29:36.153926096 +0800
  • mv 1.txt 2.txt / chmod 666 1.txt 等会变更inode信息的操作会使ctime改变,atime 和 mtime不变
[root@centos01 ~]# chmod 666 1.txt
[root@centos01 ~]# stat 1.txt
  File: `1.txt'
  Size: 4               Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d      Inode: 931337      Links: 1
Access: (0666/-rw-rw-rw-)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-02-27 22:24:24.653927639 +0800
Modify: 2016-02-27 22:29:36.153926096 +0800
Change: 2016-02-27 22:30:44.079913921 +0800
  • mtime 改变一定会导致 ctime 改变
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值