What does the output of return os.lstat(logFile)[ST_CTIME] mean?

Discussion in 'Python' started by alberttresens, Jul 26, 2010.

  1. Hi,
    I am trying to get the creation time of a file to be able to correlate it's
    content timestamps with other log files.
    In order to get the creation time of the file one a Linux machine i used:

    return os.lstat(logFile)[ST_CTIME]

    That returns to me something like: 1279620166

    I would like to know the meaning of this number.
    Is it in seconds since the epoch?
    Or is some other respresentation?

    Thanks,
    Albert
    --
    View this message in context: http://old.nabble.com/What-does-the...ile)-ST_CTIME--mean--tp29268605p29268605.html
    Sent from the Python - python-list mailing list archive at Nabble.com.
    alberttresens, Jul 26, 2010
    #1
    1. Advertising

  2. Re: What does the output of return os.lstat(logFile)[ST_CTIME]mean?

    On Mon, 26 Jul 2010 09:54:23 -0700, alberttresens wrote:

    > Hi,
    > I am trying to get the creation time of a file to be able to correlate
    > it's content timestamps with other log files. In order to get the
    > creation time of the file one a Linux machine i used:


    You're out of luck. Neither Unix nor Linux store the creation time of
    files, at least not on any file system I know of. It stores three
    timestamps: mtime, ctime, and atime.

    atime is the simple one -- it is "access time", or when the file was last
    read.

    mtime is "modification time" -- it is when the file *contents* were last
    changed.

    But ctime is NOT creation time, as many people imagine. It is "change
    time", and it changes whenever EITHER the file contents are changed, OR
    when the file metadata (permissions, owner, name, etc.) change.

    So any time mtime changes, so does ctime. But not visa versa.


    > return os.lstat(logFile)[ST_CTIME]
    >
    > That returns to me something like: 1279620166
    >
    > I would like to know the meaning of this number. Is it in seconds since
    > the epoch?


    Yes.




    --
    Steven
    Steven D'Aprano, Jul 26, 2010
    #2
    1. Advertising

  3. Hi, thanks for the reply.

    But what i am more concerned about, as I am trying to correlate logs, is
    what is the timestamp:
    1279620166 mean?
    Is it seconds since the epoch or the ISO time in seconds?

    Any idea?

    Thanks a lot!!


    Steven D'Aprano-7 wrote:
    >
    > On Mon, 26 Jul 2010 09:54:23 -0700, alberttresens wrote:
    >
    >> Hi,
    >> I am trying to get the creation time of a file to be able to correlate
    >> it's content timestamps with other log files. In order to get the
    >> creation time of the file one a Linux machine i used:

    >
    > You're out of luck. Neither Unix nor Linux store the creation time of
    > files, at least not on any file system I know of. It stores three
    > timestamps: mtime, ctime, and atime.
    >
    > atime is the simple one -- it is "access time", or when the file was last
    > read.
    >
    > mtime is "modification time" -- it is when the file *contents* were last
    > changed.
    >
    > But ctime is NOT creation time, as many people imagine. It is "change
    > time", and it changes whenever EITHER the file contents are changed, OR
    > when the file metadata (permissions, owner, name, etc.) change.
    >
    > So any time mtime changes, so does ctime. But not visa versa.
    >
    >
    >> return os.lstat(logFile)[ST_CTIME]
    >>
    >> That returns to me something like: 1279620166
    >>
    >> I would like to know the meaning of this number. Is it in seconds since
    >> the epoch?

    >
    > Yes.
    >
    >
    >
    >
    > --
    > Steven
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    >


    --
    View this message in context: http://old.nabble.com/What-does-the...ile)-ST_CTIME--mean--tp29268605p29268871.html
    Sent from the Python - python-list mailing list archive at Nabble.com.
    alberttresens, Jul 26, 2010
    #3
  4. On 07/26/2010 07:24 PM, alberttresens wrote:
    >
    > Hi, thanks for the reply.


    Alas, you didn't actually read it:

    >
    > But what i am more concerned about, as I am trying to correlate logs, is
    > what is the timestamp:
    > 1279620166 mean?
    > Is it seconds since the epoch or the ISO time in seconds?
    >
    > Any idea?
    >
    > Thanks a lot!!
    >


    [...]

    >>> I would like to know the meaning of this number. Is it in seconds since
    >>> the epoch?

    >>
    >> Yes.


    You quoted the answer to your question in the same e-mail. fascinating.

    A little side note:

    >> atime is the simple one -- it is "access time", or when the file was
    >> last read.


    You should never rely on this, though: some file systems don't store
    this (I think) and many users/sysadmins actually disable this
    (mount -o noatime) for performance reasons. (Also, on an SSD, I imagine
    enabling atime, and with it many, many additional writes, could
    noticeably detriment disk lifetime)
    Thomas Jollans, Jul 26, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Chermside

    RE: lstat(fileName)[ST_SIZE]

    Michael Chermside, Jun 10, 2005, in forum: Python
    Replies:
    0
    Views:
    408
    Michael Chermside
    Jun 10, 2005
  2. Hitesh

    ST_CTIME convert to yyyymmdd

    Hitesh, Aug 7, 2006, in forum: Python
    Replies:
    1
    Views:
    536
    Hitesh
    Aug 7, 2006
  3. Adrian Petrescu

    Interpreting os.lstat()

    Adrian Petrescu, Jul 19, 2007, in forum: Python
    Replies:
    9
    Views:
    599
    =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=
    Jul 21, 2007
  4. Giampaolo Rodola'

    Is os.lstat available on all platforms?

    Giampaolo Rodola', Nov 29, 2007, in forum: Python
    Replies:
    2
    Views:
    236
    Giampaolo Rodola'
    Nov 29, 2007
  5. onLINES

    lstat() and stat()

    onLINES, Sep 30, 2008, in forum: C Programming
    Replies:
    4
    Views:
    419
    Joachim Schmitz
    Sep 30, 2008
Loading...

Share This Page