簡體   English   中英

如何在Linux中設置文件時間范圍?

[英]How do I set file timesamps in Linux?

我需要更新C程序中現有文件的文件時間戳(即st_ctimest_atimest_mtime )。

在Win32上,我可以使用SetFileTime來更新時間戳。

我如何在Linux上實現相同的目標?


編輯
我知道touch但因為我已經在問題中加了一個C標簽,我希望我可以通過系統調用而不是調用外部命令來完成它...

您正在尋找utimensatfutimens

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM