linux - 文件打开后访问时间不变

标签 linux filesystems mount

我正在使用 stat 获取文件的访问时间(当前日期是 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

然后我编辑文件,不做任何修改关闭,再次提交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]$

挂载命令的输出是

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

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

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw) 

devpts on /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)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_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 (e.g., 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.

关于linux - 文件打开后访问时间不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19551139/

相关文章:

linux - 当我尝试编译时生成 : Nothing to be done for `all' .

linux - 当 Linux 操作系统非正常关闭/重置时,如何防止文件/磁盘损坏?

windows - 目录中有多少个文件太多(在 Windows 和 Linux 上)?

docker - Docker数据卷和挂载到主机

linux - 在 bash 关联数组中使用变量作为键

linux - git pull & git clone hang - Linux Ubuntu

python - 值错误 : Mountpoint must not contain a space. (Colab)

linux - 通过 fuse 挂载本地分区

linux - 使用 chroot 运行 snmp 没有给出当前值

linux - 为不同的 block 设备使用不同的 Linux I/O 调度器