[英]How do I set file timesamps in Linux?
我需要更新C程序中現有文件的文件時間戳(即st_ctime
, st_atime
, st_mtime
)。
在Win32上,我可以使用SetFileTime
來更新時間戳。
我如何在Linux上實現相同的目標?
編輯
我知道touch
但因為我已經在問題中加了一個C
標簽,我希望我可以通過系統調用而不是調用外部命令來完成它...
您正在尋找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 - 以納秒精度更改文件時間戳
我不確定您是否可以更改文件的創建時間,但您可以使用utime函數來更改訪問權限和修改時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.