如何在Linux中获取"文件创建时间"

use*_*699 4 c++ linux porting

我需要找出在Linux中使用C++创建文件的时间和日期.

Gri*_*han 7

如何获取上次修改文件的日期?.

struct stat attrib;                 //1. create a file attribute structure
stat("file_name", &attrib);         //2. get the attributes of afile.txt
clock = gmtime(&(attrib.st_mtime)); //3. Get the last modified time and
                                    // put it into the time structure
Run Code Online (Sandbox Code Playgroud)

4.8文件时间更新:

在Linux中:与文件关联的三个不同时间戳:

  • 上次访问内容的时间(atime),
  • 上次修改内容的时间(mtime),
  • 和最后一次修改inode的时间(元数据ctime).

所以,不,你不能找到文件的创建时间.(参考).一些与您有关的有用链接问题:


h22*_*h22 0

获得准确的创建时间似乎并不容易,但您可以获得上次修改、上次访问和上次状态更改的时间。

您需要使用sys/stat.h 中定义的结构 stat 。这是有关如何获取和使用此结构的文档。