0

这是我想要做的事情:我需要知道何时文件被工具(例如编译器)读取或使用。我使用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 上运行

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

4

1 回答 1

1

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

引自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.
于 2013-12-04T07:35:08.520 回答