加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

atime ctime mtime的影响

发布时间:2020-12-14 01:09:29 所属栏目:Linux 来源:网络整理
导读:在linux系统中,文件是时间戳属性有三个 Access Modify Change 这三个可以通过 stat 命令来查看 相应的,find命令中有三个参数atime mtime ctime分别呢对应着Access、Modify、Change 配合着相应的参数,可以用来查找相应时间范围内的文件,按照文档解释 简名
在linux系统中,文件是时间戳属性有三个

  • Access
  • Modify
  • Change

这三个可以通过 stat 命令来查看

相应的,find命令中有三个参数atime mtime ctime分别呢对应着Access、Modify、Change 配合着相应的参数,可以用来查找相应时间范围内的文件,按照文档解释

简名 全名 中文名 含义
atime access time 访问时间 文件中的数据库最后被访问的时间
mtime modify time 修改时间 文件内容被修改的最后时间
ctime change time 变化时间 文件的元数据发生变化。

什么样的操作会影响这三个时间,这个就是比较模糊的。为了搞清楚,先来做一些操作来验证一下。
创建一个文件

touch  timestamp

然后来查看一下这个文件的三个时间戳

$ stat timestamp
  File: `timestamp‘
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:50:53.000000000 +0800
Change: 2019-05-18 16:50:53.000000000 +0800

以下就是验证操作:

  • echo命令
echo ‘test‘ >> timestamp
  File: `timestamp‘
  Size: 5           Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:50:59.000000000 +0800
Change: 2019-05-18 16:50:59.000000000 +0800

可以看到 mtime与ctime都发生了改变,但是atime没有变化

  • vim

使用vim在做操作

vim timestamp
  File: `timestamp‘
  Size: 7           Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800

同样的 mtime与ctime都发生了改变,但是atime没有变化

  • ls more less cp cat
    再用ls命令查看一下
ls timestamp
timestamp

$ stat timestamp
  File: `timestamp‘
  Size: 7           Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800
$ cat timestamp
testaa

$ stat timestamp
  File: `timestamp‘
  Size: 7           Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800
$ more timestamp
testaa

$ stat timestamp
  File: `timestamp‘
  Size: 7           Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:51:58.000000000 +0800

三个时间都没有变化

注意,关于查看文件内容atime没有发生变化,可能会有一些歧义。Linux kernel2.6.20开始为mount引入了一个 relatime 选项,并从 2.6.30 开始这一选项默认是开启的。
当开启了 relatime 选项后,只有当 atime<mtime 或 atime<ctime 时,才会去更新 atime. 默认情况下,内核高于2.6.30,直接查看文件内容,atime不会变化。

  • chmod chown
$ chmod 777 timestamp
$ stat timestamp
  File: `timestamp‘
  Size: 7           Blocks: 8          IO Block: 4096   regular file
Device: fc01h/64513d    Inode: 802838      Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-05-18 16:50:53.000000000 +0800
Modify: 2019-05-18 16:51:58.000000000 +0800
Change: 2019-05-18 16:56:31.000000000 +0800

ctime变化

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读