如何更改文件的上次访问?

How can I change file's last access?

提问人:StudentOrint 提问时间:4/24/2022 最后编辑:StudentOrint 更新时间:4/25/2022 访问量:188

问:

如何通过 linux 和在 linux 中更改文件的上次访问?
(例如,要将文件的上次访问更新为:
utimemktime
11 (seconds) : 11 (minutes) : 11 (hour) : 11 (day) : 11 (month) : 1500 (year) )

我知道我可以通过命令来做到这一点,但我试图通过这些系统调用来做到这一点。想法?touch

Linux C++11 MKTimim

评论

0赞 जलजनक 4/24/2022
选择一种编程语言并分享你到目前为止编写的代码。
0赞 StudentOrint 4/24/2022
编程语言: C++11 @जलजनक

答:

0赞 Philippe 4/24/2022 #1

您使用 utimensat : utimensat

utimensat() 和 futimens() 用 纳秒精度。这与历史形成鲜明对比 utime(2) 和 utimes(2),它们只允许秒和微秒 精度。

   With utimensat() the file is specified via the pathname given in
   pathname.  With futimens() the file whose timestamps are to be
   updated is specified via an open file descriptor, fd.

   For both calls, the new file timestamps are specified in the
   array times: times[0] specifies the new "last access time"
   (atime); times[1] specifies the new "last modification time"
   (mtime).  Each of the elements of times specifies a time as the
   number of seconds and nanoseconds since the Epoch, 1970-01-01
   00:00:00 +0000 (UTC).  This information is conveyed in a