Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ctime, atime, and mtime - How to interpret them?

Tags:

python

linux

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.

like image 840
user823743 Avatar asked Dec 18 '14 14:12

user823743


People also ask

What does mtime 0 mean?

mtime 0 finds files modified between now and 1 day ago.

What does mtime mean in Linux?

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.

What is St_atime St_mtime and St_ctime?

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.

What are the different timestamps associated with a file?

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 ).


1 Answers

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.

like image 183
Marc B Avatar answered Sep 22 '22 17:09

Marc B