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

编程入门 行业动态 更新时间:2024-10-10 19:25:15
本文介绍了打开文件后,访问时间不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

[juan]

我使用stat来获取文件的存取时间(当前日期为2013年10月23日) @ JN-LNXSVR-02 labfiles] $ stat nursery 文件:`nursery'大小:837个块:8个IO块:4096个常规文件设备:fd00h / 64768d Inode:139539链接: 1 存取:(0644 / -rw-r - r--)Uid:(500 / juan)Gid:(500 / juan)存取:2013-10-22 18:03:20.703888346 -0400 修改:2013-10-21 16:57:07.801165793 -0400

然后我编辑文件并关闭它,不做任何修改,然后再次提交stat $ $ $ $ c $ j $ JN-LNXSVR-02 labfiles $ vi nursery 文件:`nursery'大小:837个块:8个IO块:4096个常规文件设备:fd00h [juan @ JN-LNXSVR-02 labfiles] $ stat nursery / 64768d inode:139539链接:1 访问:(0644 / -rw-r - r--)Uid:500 / juan Gid:500 / juan 访问:2013-10 -22 18:03:20.703888346 -04 00 修改:2013-10-21 16:57:07.801165793 -0400 更改:2013-10-21 16:57:07.801165793 -0400 pre>

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

我找不到任何noatime属性

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

mount命令的输出是 $ $ p $ j $ JN $ LNXSVR-02 labfiles $ mount / dev / mapper / vg_jnlnxsvr02 -lv_root on / type ext4(rw) proc on / proc type proc(rw) sysfs on / sys类型/ dev / pts类型devpts(rw,gid = 5,mode = 620) 在/ dev / shm类型上的tmpfs tmpfs(rw, rootcontext =system_u:object_r:tmpfs_t:s0) $ b $ / dev / sda1 on / boot type ext4(rw) / proc / sys / fs / binfmt_misc输入binfmt_misc(rw) 在/ var / lib / nfs / rpc_pipefs上输入sunrpc输入rpc_pipefs(rw) $ b $ j $ JN $ LN $ s $ $

解决方案您可以包含 mount 的输出吗?也许你的磁盘挂载了 noatime ?

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

考虑到您的访问时间已经比您的修改时间更新,访问时间将 b $ b

来自 man mount :

noatime 不要更新这个文件系统的inode访问时间(例如,为了更快地访问的新闻假脱机来加速新闻服务器)。 relatime 更新相对于修改或更改时间的inode访问时间。访问时间是,只有当前访问时间早于当前修改或更改时间时才更新。 (类似于noatime,但不会中断Mutt或其他应用程序,它们需要知道自上次修改文件以来是否读取了文件)由于Linux 2.6.30,内核默认到这个选项提供的行为(除非指定noatime),strictatime选项需要来获得传统的语义。另外,从Linux 2.6.30开始,如果文件的最后访问时间超过1天,则总是会更新。

为了记录,如果您希望返回旧的行为,请使用 strictatime 。

允许显式请求完整的atime更新。这使内核有可能默认为relatime或noatime,但仍然允许用户空间覆盖 it。有关默认系统安装选项的更多详细信息,请参阅/ proc / mounts。

I am using stat to get the acess time of a file (current date is October 23, 2013)

[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

then I edit the file and close it without any modification, and submit stat again

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

but the access time did not change, why?

I could not find any noatime attribute

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

The output of the mount command is

[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]$

解决方案

Could you include the output of mount? Maybe your disk is mounted with noatime?

EDIT (again): relatime would only update it once when reading after a modification but not every time. Since Linux 2.6.30 this seems to be the standard option, so if you do write + read it would update on the read. But write + read + read would only update it for the first read (and once after every following modification).

Given that your access time is already newer than your modification time, the access time would not be updated when mounted with relatime (or without atime option) if you only read.

from 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.

And for the record, if you want to have the old behaviour back, use 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.

更多推荐

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

本文发布于:2023-11-13 11:10:25,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!