上次访问时间未更新?

时间:2013-12-04 06:40:45

标签: bash ubuntu time ubuntu-12.04 lastaccesstime

以下是我要做的事情:我需要知道工具(例如编译器)读取或使用文件的时间。我使用ls使用以下命令

获取上次访问的时间
ls -l --time=access -u --sort=time --time-style=+%H:%M:%S

stat "filename"

但是我的文件访问时间没有得到更新,我认为是因为缓存!如果我错了请纠正我。所以我的下一步是如何清除缓存,研究它我遇到了以下命令的一些变体:

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

即使执行此命令后,我的文件访问时间也没有更新! 我测试访问时间的方法是在 gEdit 中打开文件或在我的源文件上调用gcc

我的设置:在VMware上运行的Ubunto 12.0.4,在Win 7上运行

问题:我错过了什么或做错了我的访问时间没有更新?

1 个答案:

答案 0 :(得分:1)

您正在观察的是从2.6.30开始的默认mount选项的更改,以实现文件系统性能改进

引自man mount

   relatime
          Update inode access times relative to  modify  or  change  time.
          Access time is only updated if the previous access time was ear‐
          lier than the current modify or change time. (Similar  to  noat‐
          ime,  but  doesn't break mutt or other applications that need to
          know if a file has been read since the last time  it  was  modi‐
          fied.)

          Since Linux 2.6.30, the kernel defaults to the behavior provided
          by this option (unless noatime was  specified), and the stricta‐
          time  option  is  required  to  obtain traditional semantics. In
          addition, since Linux 2.6.30, the file's  last  access  time  is
          always  updated  if  it  is more than 1 day old.

(另请参阅thisthis。)您可能正在寻找以下mount选项:

   strictatime
          Allows to explicitly requesting full atime updates.  This  makes
          it  possible  for  kernel to defaults to relatime or noatime but
          still allow userspace to override it. For more details about the
          default system mount options see /proc/mounts.