Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file creation time with Python on linux

Tags:

os.stat returns st_mtime and st_ctime attributes, the modification time is st_mtime and st_ctime "change time" on POSIX. is there any function that return the creation time of a file using python and under Linux?

like image 940
Ali Mezgani Avatar asked Sep 10 '09 23:09

Ali Mezgani


People also ask

How do you get the date and time a file was created in Linux?

To find a file creation date and time “crtime” is to find the inode of the file using the stat command against a file called “About-TecMint”. Alternatively, you can use the ls -i command against a file called “About-TecMint”.

How can you find the creation date of a file?

Windows file properties You can also see the modified date by viewing the file properties. Right-click the file and select Properties. In the Properties window, the Created date, Modified date, and Accessed date is displayed, similar to the example below.


2 Answers

You probably can't.:

3.1)  How do I find the creation time of a file?        You can't - it isn't stored anywhere.  Files have a last-modified       time (shown by "ls -l"), a last-accessed time (shown by "ls -lu")       and an inode change time (shown by "ls -lc"). The latter is often       referred to as the "creation time" - even in some man pages -       but that's wrong; it's also set by such operations as mv, ln,       chmod, chown and chgrp.        The man page for "stat(2)" discusses this. 
like image 131
SingleNegationElimination Avatar answered Nov 05 '22 13:11

SingleNegationElimination


try:

st_birthtime 

It isnt' guaranteed to be available on all systems though. From the docs:

On some Unix systems (such as Linux), the following attributes may also be available: st_blocks (number of blocks allocated for file), st_blksize (filesystem blocksize), st_rdev (type of device if an inode device). st_flags (user defined flags for file).

On other Unix systems (such as FreeBSD), the following attributes may be available (but may be only filled out if root tries to use them): st_gen (file generation number), st_birthtime (time of file creation).

http://docs.python.org/2/library/os.html#os.stat

like image 33
Jon Avatar answered Nov 05 '22 14:11

Jon