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 tim
According to a thread here OS X's HFS and Microsoft's NTFS also both track the birth time, and I'm told the OS X and Cygwin versions of stat() return this information. which looking at the osx stat manpage seems correct at least for mac:
a, m, c, B
The time file was last accessed or modified, of when the inode was last changed, or the birth time of the inode.
For linux newer filesystems like ext4, Btrfs and JFS do support this using debugfs, there is a bash function taken from here that will extract the date-created timestamp:
You may recover the file creation date if you deal with capable filesystem like EXT4 - journaling file system for Linux:
Improved timestamps
... Ext4 provides timestamps measured in nanoseconds. In addition, ext4 also adds support for date-created timestamps. But there no consensus in the community on that so
... as Theodore Ts'o points out, while it is easy to add an extra creation-date field in the inode (thus technically enabling support for date-created timestamps in ext4), it is more difficult to modify or add the necessary system calls, like stat() (which would probably require a new version) and the various libraries that depend on them (like glibc). These changes would require coordination of many projects. So even if ext4 developers implement initial support for creation-date timestamps, this feature will not be available to user programs for now. Which end up with the Linus final quote
Let's wait five years and see if there is actually any consensus on it being needed and used at all, rather than rush into something just because "we can".
xstat() {
for target in "${@}"; do
inode=$(ls -di "${target}" | cut -d ' ' -f 1)
fs=$(df "${target}" | tail -1 | awk '{print $1}')
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null |
grep -oP 'crtime.*--\s*\K.*')
printf "%s\t%s\n" "${crtime}" "${target}"
done
}
Running it returns the creation date:
:~$ echo 'print("hello world")' > blah.py
:~$ xstat "blah.py"
Mon Jul 6 13:43:39 2015 blah.py
:~$ echo 'print("goodbye world")' > blah.py
:~$ xstat "blah.py"
Mon Jul 6 13:43:39 2015 blah.py
So unless the file system supports it then it is not possible, if the file system does then you could run the debugfs
using subprocess and parse the output.