bash - 上次访问时间未更新?

标签 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 上运行

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

最佳答案

您正在观察的是默认 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.

关于bash - 上次访问时间未更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20368734/

相关文章:

bash - Bash-为什么$(sudo cat file)找不到存在的文件?

python - 如何在ubuntu/linux中添加人脸识别登录?

linux - 如何生成 fullchain.pem 和 privkey.pem?

python - 如何在 Ubuntu 上运行的 Python 应用程序中加载 .so 库

c - MPI 总运行时间

time - Selenium 中 waitForPageToLoad 的替代方案

bash - Awk 将双引号字符串视为一个标记并忽略其间的空格

bash - -bash : vim: command not found

linux - Unix 天才 - 从一堆文件名中删除 "."?

ruby-on-rails - 就地编辑时间对象