I am writing a program in Python that requires comparison of atime, mtime, and ctime of several directories. For this purpose I am using os.stat("my_directory/")
. What I get as a result is a string which includes these times. For a sample directory I have:
st_atime=1418911410L
st_mtime=1418911410L
st_ctime=1404656050L
My problem is that I have some confusion with these numbers. I would like to know if these numbers are convertible to actual time? or, if one number (lets say ctime) is smaller than the other (like atime), does it mean that ctime is earlier than atime or later? I have searched many websites to learn this, but my attempts went without a success. Could anyone help me? thanks in advance.
mtime 0 finds files modified between now and 1 day ago.
Every Linux file has three timestamps: the access timestamp (atime), the modified timestamp (mtime), and the changed timestamp (ctime). The access timestamp is the last time a file was read. This means someone used a program to display the contents of the file or read some values from it.
st_atime: It represents the time of most recent access. It is expressed in seconds. st_mtime: It represents the time of most recent content modification. It is expressed in seconds. st_ctime: It represents the time of most recent metadata change on Unix and creation time on Windows.
Digital timestamps In particular, most modern operating systems support the POSIX stat (system call), so each file has three timestamps associated with it: time of last access (atime: ls -lu ), time of last modification (mtime: ls -l ), and time of last status change (ctime: ls -lc ).
ctime - the last time the file's inode was changed (e.g. permissions changed, file renamed, etc..)
mtime - last time the file's CONTENTS were changed
atime - last time the file was accessed.
The numbers are simply unix timestamps - signed 32bit ints representing seconds since Jan 1/1970, aka the epoch.
And yes, smaller numbers = earlier in time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With