[英]How do I set file timesamps in Linux?
I need to update file timestamps (namely st_ctime
, st_atime
, st_mtime
) of an existing file in a C program. 我需要更新C程序中现有文件的文件时间戳(即st_ctime
, st_atime
, st_mtime
)。
On Win32, I could use SetFileTime
to update the timestamps. 在Win32上,我可以使用SetFileTime
来更新时间戳。
How do I achieve the same on Linux? 我如何在Linux上实现相同的目标?
Edit 编辑
I know touch
but since I've put a C
tag to the question, I hoped that I could do it with a system call instead of calling an external command... 我知道touch
但因为我已经在问题中加了一个C
标签,我希望我可以通过系统调用而不是调用外部命令来完成它...
You are looking for utimensat
or futimens
: 您正在寻找utimensat
或futimens
:
int utimensat(int dirfd, const char *pathname,
const struct timespec times[2], int flags);
int futimens(int fd, const struct timespec times[2]);
utimensat, futimens - change file timestamps with nanosecond precision utimensat,futimens - 以纳秒精度更改文件时间戳
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.