C 程序更改 linux 中的文件时间戳
C program to change the files timestamp in linux
我正在编写一个 C 程序来更改 linux 中文件的修改时间戳(时间和日期)。我找到了它的命令,但我正在寻找一种方法,我可以通过 C 程序来做到这一点。有什么办法可以做到吗?
可以,通过使用 system()
函数和 touch
Linux 命令。来自 system() manual page :
int system(const char *command);
The system() library function uses... that executes the shell command specified in command
编辑:这会将时间戳更新为当前时间和日期。
为了linux试试
int utimensat(int dirfd, const char *pathname,
const struct timespec times[2], int flags);
或旧命令
int utime(const char *filename, const struct utimbuf *times);
我正在编写一个 C 程序来更改 linux 中文件的修改时间戳(时间和日期)。我找到了它的命令,但我正在寻找一种方法,我可以通过 C 程序来做到这一点。有什么办法可以做到吗?
可以,通过使用 system()
函数和 touch
Linux 命令。来自 system() manual page :
int system(const char *command);
The system() library function uses... that executes the shell command specified in command
编辑:这会将时间戳更新为当前时间和日期。
为了linux试试
int utimensat(int dirfd, const char *pathname,
const struct timespec times[2], int flags);
或旧命令
int utime(const char *filename, const struct utimbuf *times);