Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Finding the absolute creation time of a file

by Sihal (Pilgrim)
on Apr 09, 2003 at 08:09 UTC ( [id://249164]=perlquestion: print w/replies, xml ) Need Help??

Sihal has asked for the wisdom of the Perl Monks concerning the following question:

When using the command "ls -rlt --time=ctime -F --full-time" under gnu/linux, I can get the absolute creation time of a file.
It seems that I cannot do the same with the stat function, since I can only get the mtime... wich is fine if my files are not modified.... but they are.
Am I missing something about stat, about gnu/linux in general ( :) ) or ?
Thanks in advance ! Sihal
  • Comment on Finding the absolute creation time of a file

Replies are listed 'Best First'.
Re: Finding the absolute creation time of a file
by Abigail-II (Bishop) on Apr 09, 2003 at 09:06 UTC
    It's a myth that you can get the absolute creation time of a file under Unix. No such information is stored. Besides, when is a file created? Suppose a file named orig is created at time T0, and at time T1 happens one of the following:
    mv orig new mv orig /some/other/file/system/new cp orig new ln orig new echo "Foo" >> orig echo "Foo" > orig vi orig cp /etc/password orig

    What would be the "absolute creation time" of new, and what happens to the "absolute creation time" of orig in all those cases?

    Abigail

      true, true... Guess I'll have to change the way my prog operates then, if I can't rely on this. Thanx all for the feedback .
Re: Finding the absolute creation time of a file
by Enlil (Parson) on Apr 09, 2003 at 08:24 UTC
    From the gnu fileutils docs:

    ...the inode change time. This is often referred to as a file's ctime. The inode change time represents the time when the file's meta-information last changed. "

    which i believe is the same as the 11th element returned by stat.

    I am not really sure you can get an absolute creation time of any file after the ctime has changed (since this does not happen only at creation), though I could be wrong.

    -enlil

Re: Finding the absolute creation time of a file
by robartes (Priest) on Apr 09, 2003 at 08:30 UTC
    Unfortunately, you can't get an absolute creation time of a file under Unix (not even with your command line). What your command line gets is the same as the 11th field of Perl stat, which is the inode change time. An inode contains the meta information of a file (size etc). Whenever you do something that changes the inode (e.g. add to it, so its size changes), the ctime is updated. There is no way to get the creation time of a file from the filesystem.

    CU
    Robartes-

      <quote> What your command line gets is the same as the 11th field of Perl stat, which is the inode change time.</quote> Are you sure ? Cause when copying the files using the -p options, it preserves the timestamps, and I retain the same info as my original file, so I'm not sure that what I'm getting with my command is the ctime...
      But that's why I'm asking the question, cause I'm confused :)
        Are you sure ? Cause when copying the files using the -p options, it preserves the timestamps, and I retain the same info as my original file

        Well, it stands to reason that when you ask to preserve the timestamps, they are preserved :).

        But yes, I'm quite sure - ctime in Unix filesystem is the inode change time, not creation time. Take a look at the man page for the stat system call. Then take a look at this.

        CU
        Robartes-

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://249164]
Approved by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2025-02-08 03:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (95 votes). Check out past polls.