打开文件后,访问时间不会更改

我正在使用stat来获取文件的存取时间(当前date是2013年10月23日)

[juan@JN-LNXSVR-02 labfiles]$ stat nursery File: `nursery' Size: 837 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 139539 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 500/ juan) Gid: ( 500/ juan) Access: 2013-10-22 18:03:20.703888346 -0400 Modify: 2013-10-21 16:57:07.801165793 -0400 

然后我编辑文件并closures它,不做任何修改,并再次提交stat

 juan@JN-LNXSVR-02 labfiles]$ vi nursery [juan@JN-LNXSVR-02 labfiles]$ stat nursery File: `nursery' Size: 837 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 139539 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 500/ juan) Gid: ( 500/ juan) Access: 2013-10-22 18:03:20.703888346 -0400 Modify: 2013-10-21 16:57:07.801165793 -0400 Change: 2013-10-21 16:57:07.801165793 -0400 

但访问时间没有改变,为什么?

我找不到任何noatime属性

 juan@JN-LNXSVR-02 labfiles]$ grep noatime /proc/mounts [juan@JN-LNXSVR-02 labfiles]$ 

mount命令的输出是

 [juan @ JN-LNXSVR-02 labfiles] $ mount

 / dev / mapper / vg_jnlnxsvr02-lv_root on / type ext4(rw)

 proc on / proc type proc(rw)

 / sys上的sysfs sysfs(rw) 

 dev / dev / pts type devpts(rw,gid = 5,mode = 620) 

 tmpfs on / dev / shm type tmpfs(rw,rootcontext =“system_u:object_r:tmpfs_t:s0”)


 / dev / sda1 on / boot type ext4(rw)
 none / on / proc / sys / fs / binfmt_misc type binfmt_misc(rw)

 / var / lib / nfs / rpc_pipefs上的sunrpctypesrpc_pipefs(rw)

 [juan @ JN-LNXSVR-02 labfiles] $ 

你可以包含mount的输出吗? 也许你的磁盘挂载noatime

编辑(再次)relatime将只更新一次,当修改后读取,但不是每次。 由于Linux 2.6.30这似乎是标准的选择,所以如果你write + read它会更新读取。 但是write + read + read只会在第一次读取时更新(以及每次修改之后)。

考虑到您的访问时间已经比您的修改时间更新,如果您只读取,则在使用relatime (或没有atime选项)进行挂载时,访问时间将不会更新。

man mount

 noatime Do not update inode access times on this filesystem (eg, for faster access on the news spool to speed up news servers). relatime Update inode access times relative to modify or change time. Access time is only updated if the previous access time was earlier than the current modify or change time. (Similar to noatime, but doesn't break mutt or other applications that need to know if a file has been read since the last time it was modified.) Since Linux 2.6.30, the kernel defaults to the behavior provided by this option (unless noatime was specified), and the strictatime 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. 

而为了记录,如果你想让旧的行为回来,使用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.