开发者社区> 问答> 正文

Linux中stat命令,access time的疑问:报错

stat [filename]

显示的access time应该是最近一次访问改文件的时间。包括读取和写入。

但是,我无论用less读取还是用编辑器打开修改内容,或者用echo 1 >> [filename]也不会改变access time。(后两者实际上已经改变了文件的实际内容和inode信息了,所以ctime和mtime都已经改变了,但是atime没有变!)

只有当我用编辑器打开,移动光标后,access time才改变了。

这是为什么呢?这个access time怎么这么不靠谱?

展开
收起
kun坤 2020-06-06 16:58:33 685 0
1 条回答
写回答
取消 提交回答
  • 找到答案了,还是wiki给力阿。

    atime updates are by far the biggest IO performance deficiency that Linux has today. Getting rid of atime updates would give us more everyday Linux performance than all the pagecache speedups of the past 10 years, _combined_.

    As of 2.6.30 (9 June 2009), Linux defaults to relatime,[3] so that it will not update atime on all file reads. The behavior offers sufficient performance for most purposes and should not break any significant applications. Extended discussion of filesystem performance preceded the decision.[4] Indeed, relatime by default was the first patch Linux applied following the 2.6.29 release. In initial patches relatime only updated atime if atime < mtime or atime < ctime;

    ######经实验,正确。和光标移动无关(之前是恰好修改文件后进行了光标移动)######atime是最近访问时间。。。。顾名思义。。。你cat一下它就会变了。。。。。######cat 后,access time没有改变。######

    引用来自“$_$”的答案

    atime是最近访问时间。。。。顾名思义。。。你cat一下它就会变了。。。。。

    你的机器上是变的吗?

    这是我的结果:

    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS
      File: `AUTHORS'
      Size: 365           Blocks: 8          IO Block: 4096   regular file
    Device: 803h/2051d    Inode: 9439976     Links: 1
    Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi)
    Access: 2012-08-29 18:57:35.430069290 +0800
    Modify: 2012-08-29 18:57:35.354069292 +0800
    Change: 2012-08-29 18:57:35.354069292 +0800
     Birth: -
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ cat AUTHORS
    Tim Ansell <mithro@mithis.net>
    Phil Blundell <pb@handhelds.org>
    Seb Frankengul <seb@frankengul.org>
    Holger Freyther <holger@moiji-mobile.com>
    Marcin Juszkiewicz <marcin@juszkiewicz.com.pl>
    Chris Larson <kergoth@handhelds.org>
    Ulrich Luckas <luckas@musoft.de>
    Mickey Lauer <mickey@Vanille.de>
    Richard Purdie <rpurdie@rpsys.net>
    Holger Schurig <holgerschurig@gmx.de>
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS
      File: `AUTHORS'
      Size: 365           Blocks: 8          IO Block: 4096   regular file
    Device: 803h/2051d    Inode: 9439976     Links: 1
    Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi)
    Access: 2012-08-29 18:57:35.430069290 +0800
    Modify: 2012-08-29 18:57:35.354069292 +0800
    Change: 2012-08-29 18:57:35.354069292 +0800
     Birth: -
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ date
    Wed Aug 29 19:04:17 CST 2012
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$

    ######

    引用来自“ChenQi”的答案

    引用来自“$_$”的答案

    atime是最近访问时间。。。。顾名思义。。。你cat一下它就会变了。。。。。

    你的机器上是变的吗?

    这是我的结果:

    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS
      File: `AUTHORS'
      Size: 365           Blocks: 8          IO Block: 4096   regular file
    Device: 803h/2051d    Inode: 9439976     Links: 1
    Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi)
    Access: 2012-08-29 18:57:35.430069290 +0800
    Modify: 2012-08-29 18:57:35.354069292 +0800
    Change: 2012-08-29 18:57:35.354069292 +0800
     Birth: -
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ cat AUTHORS
    Tim Ansell <mithro@mithis.net>
    Phil Blundell <pb@handhelds.org>
    Seb Frankengul <seb@frankengul.org>
    Holger Freyther <holger@moiji-mobile.com>
    Marcin Juszkiewicz <marcin@juszkiewicz.com.pl>
    Chris Larson <kergoth@handhelds.org>
    Ulrich Luckas <luckas@musoft.de>
    Mickey Lauer <mickey@Vanille.de>
    Richard Purdie <rpurdie@rpsys.net>
    Holger Schurig <holgerschurig@gmx.de>
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS
      File: `AUTHORS'
      Size: 365           Blocks: 8          IO Block: 4096   regular file
    Device: 803h/2051d    Inode: 9439976     Links: 1
    Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi)
    Access: 2012-08-29 18:57:35.430069290 +0800
    Modify: 2012-08-29 18:57:35.354069292 +0800
    Change: 2012-08-29 18:57:35.354069292 +0800
     Birth: -
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ date
    Wed Aug 29 19:04:17 CST 2012
    chenqi@chenqi-OptiPlex-760:~/poky/bitbake$

    我的是变的

    Jiang@local ~/tmp/test $ stat test

      文件:"test"

      大小:0         块:0          IO 块:4096   普通空文件

    设备:11h/17d Inode:268877      硬链接:1

    权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang)

    最近访问:2012-08-29 19:06:22.200085281 +0800

    最近更改:2012-08-29 19:06:22.200085281 +0800

    最近改动:2012-08-29 19:06:22.200085281 +0800

    创建时间:-

    Jiang@local ~/tmp/test $ cat test 

    Jiang@local ~/tmp/test $ stat test

      文件:"test"

      大小:0         块:0          IO 块:4096   普通空文件

    设备:11h/17d Inode:268877      硬链接:1

    权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang)

    最近访问:2012-08-29 19:06:51.364086914 +0800

    最近更改:2012-08-29 19:06:22.200085281 +0800

    最近改动:2012-08-29 19:06:22.200085281 +0800

    Jiang@local ~/tmp/test $ echo hello > test

    Jiang@local ~/tmp/test $ stat test

      文件:"test"

      大小:6         块:8          IO 块:4096   普通文件

    设备:11h/17d Inode:268877      硬链接:1

    权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang)

    最近访问:2012-08-29 19:06:51.364086914 +0800

    最近更改:2012-08-29 19:08:02.916090921 +0800

    最近改动:2012-08-29 19:08:02.916090921 +0800

    创建时间:-

    Jiang@local ~/tmp/test $ !cat

    cat test 

    hello

    Jiang@local ~/tmp/test $ stat test

      文件:"test"

      大小:6         块:8          IO 块:4096   普通文件

    设备:11h/17d Inode:268877      硬链接:1

    权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang)

    最近访问:2012-08-29 19:08:28.600092359 +0800

    最近更改:2012-08-29 19:08:02.916090921 +0800

    最近改动:2012-08-29 19:08:02.916090921 +0800

    创建时间:-

    ######你看,你的access time也不是很准确阿。当你echo hello > test后,test的access time没有改变。
    2020-06-06 16:58:38
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Alibaba Cloud Linux 3 发布 立即下载
ECS系统指南之Linux系统诊断 立即下载
ECS运维指南 之 Linux系统诊断 立即下载