文件的修改和访问时间?

Ank*_*kit 5 timestamps files

是否可以在不更改文件访问时间的情况下更改文件修改时间?

der*_*ert 5

utime/utimes系统调用,您可以随意设置访问和修改时间。因此,您可以使用stat该文件,然后utime仅更改其中之一。从手册页

姓名

utime, utimes - 更改文件上次访问和修改时间

概要

   #include <sys/types.h>
   #include <utime.h>

   int utime(const char *filename, const struct utimbuf *times);

   #include <sys/time.h>

   int utimes(const char *filename, const struct timeval times[2]);
Run Code Online (Sandbox Code Playgroud)

描述

utime() 系统调用将 filename 指定的 inode 的访问和修改时间分别更改为时间的 actime 和 modtime 字段。

如果时间为 NULL,则文件的访问和修改时间设置为当前时间。

在以下情况下允许更改时间戳:ate 权限,或者有效用户 ID 等于文件的用户 ID,或者时间为 NULL 并且进程对该文件具有写权限。

[……]