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.
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).
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".
You probablycan't.:
尝试:
但它并不能保证在所有系统上都可用。从文档中:
http://docs.python.org/2/library/os.html#os.stat
根据线程hereOS X的HFS和微软的NTFS也都跟踪出生时间,我被告知osx和Cygwin版本的stat()返回此信息。查看osx stat manpage似乎至少对mac是正确的:
a、m、c、B
对于像ext4、Btrfs和JFS这样使用debugfs的linux新文件系统,有一个从here中获取的bash函数将提取创建日期的时间戳:
运行它将返回创建日期:
因此,除非文件系统支持它,否则这是不可能的,如果文件系统支持,那么您可以使用子进程运行
debugfs
,并解析输出。相关问题 更多 >
编程相关推荐