How to get 'file creation time' in Linux

此生再无相见时 提交于 2019-12-05 14:18:21
Grijesh Chauhan

How do I get the date a file was last modified?.

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

4.8 File Times Update:

In Linux: three distinct timestamps associated with a file:

  • time of last access of contents (atime),
  • time of last modification of contents (mtime),
  • and time of last modification of the inode (metadata, ctime).

So, no, you cannot find file creation time. (reference). Some useful Links related to you question:

It seems no easy way to get exactly the creation time but you can get time of the last modification, last access and last status change.

You need to use the structure stat, defined in sys/stat.h. Here is the documentation on how to obtain and use this structure.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!