How do I get the creation date of a file?

Ruby's file class has three methods for querying time related data:
atime, ctime and mtime. None of these will give me the creation date of
a file. Anyone got a clue?

This is what the rubydoc says:
atime Returns the last access time for the named file.
ctime Returns the change time for the named file (the time at which
directory information about the file was changed, not the file itself).
mtime Returns the modification time for the named file.

Thanx,

marek

There is no such thing as a creation time of a file. That is to say such information
isn't stored in the filesystem. If you think about it, it is a somewhat vague notion.
What should be the creation time of a file that was restored from a backup tape/disk?
Or a file that is copied from one computer to another? Do you want the time
the file was created on the original machine, or the time it was created on the
current machine?

BTW, this isn't a Ruby issue. The atime, ctime, and mtime methods you
mention are just wrappers over the underlying information provided by
Posix-type file systems. Ruby is just a conduit for the information in this case
and it can't provide information like the 'create time' if it doesn't already exist
in the underlying filesystem.

Gary Wright

···

On Aug 15, 2006, at 5:05 PM, marek4130@gmail.com wrote:

Ruby's file class has three methods for querying time related data:
atime, ctime and mtime. None of these will give me the creation date of
a file. Anyone got a clue?

That's not precisely true -- the actual creation time of a file is the
last time it was modified, since a "file" is a "virtual" construct for
the benefit of humans. Files are actually represented on the filesystem
as nothing more than an index entry of sorts that tells the read-write
heads where to go looking for data stored on the drive that will be
presented as an atomic object to the user via the virtual filesystem,
and every time the file is changed in some way that index entry
disappears and is replaced by a new entry.

Thus, I suppose the "file" is created anew every time you touch the
thing.

···

On Wed, Aug 16, 2006 at 06:25:02AM +0900, gwtmp01@mac.com wrote:

On Aug 15, 2006, at 5:05 PM, marek4130@gmail.com wrote:

>Ruby's file class has three methods for querying time related data:
>atime, ctime and mtime. None of these will give me the creation
>date of
>a file. Anyone got a clue?

There is no such thing as a creation time of a file.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"A script is what you give the actors. A program
is what you give the audience." - Larry Wall

Ruby's file class has three methods for querying time related data:
atime, ctime and mtime. None of these will give me the creation date of
a file. Anyone got a clue?

There is no such thing as a creation time of a file. That is to say such information
isn't stored in the filesystem.

That is incorrect. It is however, platform specific. On BSD systems, the creation date of a file is stored, and can be retrieved using for example, stat(1). Example:

% stat /bin/ls [17:32:52]
device 234881026
inode 1928485
mode 33133
nlink 1
uid 0
gid 0
rdev 0
size 32460
atime 1155674758
mtime 1111445359
ctime 1136127994
blksize 4096
blocks 64
link

Note the ctime. You can fetch this programmatically to.

That said, the creation time is the initial modification time in so much as that it doesn't record when the file was created, but rather, when it was created on the filesystem. So your document could be 30 years old, the ctime will report the time you put it on the filesystem.

···

On 06-08-15, at 17:25, gwtmp01@mac.com wrote:

On Aug 15, 2006, at 5:05 PM, marek4130@gmail.com wrote:

Gary Wright

--
Jeremy Tregunna
jtregunna@blurgle.ca

"One serious obstacle to the adoption of good programming languages is the notion that everything has to be sacrificed for speed. In computer languages as in life, speed kills." -- Mike Vanier

Hi,

At Wed, 16 Aug 2006 06:53:39 +0900,
Jeremy Tregunna wrote in [ruby-talk:208696]:

Note the ctime. You can fetch this programmatically to.

Isn't it the change time?

It is platform specific indeed. Windows calls the creation
time as ctime.

···

--
Nobu Nakada

At Wed, 16 Aug 2006 06:53:39 +0900,
Jeremy Tregunna wrote in [ruby-talk:208696]:
> Note the ctime. You can fetch this programmatically to.

Isn't it the change time?

It is platform specific indeed. Windows calls the creation
time as ctime.

atime - last access
mtime - modified
ctime - created

Regards,
Rimantas

···

--
http://rimantas.com/

Rimantas Liubertas wrote:

At Wed, 16 Aug 2006 06:53:39 +0900,
Jeremy Tregunna wrote in [ruby-talk:208696]:
> Note the ctime. You can fetch this programmatically to.

Isn't it the change time?

It is platform specific indeed. Windows calls the creation
time as ctime.

atime - last access
mtime - modified
ctime - created

Regards,
Rimantas
--
http://rimantas.com/

Ruby docs say:

"Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself)."

-Justin

ctime - created

To clarify, as Jeremy indicated, this is actually the inode creation time.
So if you mv a file around within the same mount point, the ctime doesn't
change. If you mv accross mountpoints, a new inode gets created, and ctime
changes.

-rr-

Justin Collins wrote:

Rimantas Liubertas wrote:

At Wed, 16 Aug 2006 06:53:39 +0900,
Jeremy Tregunna wrote in [ruby-talk:208696]:
> Note the ctime. You can fetch this programmatically to.

Isn't it the change time?

It is platform specific indeed. Windows calls the creation
time as ctime.

atime - last access
mtime - modified
ctime - created

Regards,
Rimantas
--
http://rimantas.com/

Ruby docs say:

"Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself)."

-Justin

Oops, I forgot to mention that's for File.ctime:

File.ctime(file_name) => time

Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).

-Justin

It isn't the inode creation time. It is the inode *change* time. So yes, it
is set when an inode is created but it is also changed whenever information in
the inode changes such as: file ownership, file permissions, file *length*, and
so on.

Perhaps there is something like 'file creation time' or 'inode creation time'
in non-Unix, non-Posix file systems. Someone else will have to answer that
question.

As I said before, the concept of 'file creation time' is pretty fuzzy and
in any case isn't represented by any of the time stamps found in a a Posix-like
file system (atime, mtime, ctime).

···

On Aug 16, 2006, at 3:12 PM, rak rok wrote:

To clarify, as Jeremy indicated, this is actually the inode creation time.
So if you mv a file around within the same mount point, the ctime doesn't
change. If you mv accross mountpoints, a new inode gets created, and ctime
changes.

That is, effectively, creation time (for a particular definition of file
creation). It returns the time at which the file's listing in the
information for the enclosing directory changed, which basically means
when it was created within that directory. Same difference. I do think
the letter C stands for "change" in this case, though, not only in Ruby
docs, but in POSIX standards as well.

···

On Thu, Aug 17, 2006 at 04:06:39AM +0900, Justin Collins wrote:

Justin Collins wrote:
>
>Ruby docs say:
>
>"Returns the change time for the named file (the time at which
>directory information about the file was changed, not the file itself)."
>
>-Justin
>
Oops, I forgot to mention that's for File.ctime:

File.ctime(file_name) => time

Returns the change time for the named file (the time at which directory
information about the file was changed, not the file itself).

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts." - Paul Graham

man 2 stat

...
        The field st_ctime is changed by writing or by setting inode informa-
        tion (i.e., owner, group, link count, mode, etc.).
...

it's change time and this isn't even really close to creation time for __any__
definition since operations like chmod, chowner, chgrp or linking to the file
all effect this timestamp. for example

     harp:~ > touch foobar

     harp:~ > stat foobar
       File: `foobar'
       Size: 4096 Blocks: 8 IO Block: 4096 Directory
     Device: 306h/774d Inode: 278848 Links: 2
     Access: (0775/drwxrwxr-x) Uid: ( 447/ ahoward) Gid: ( 447/ ahoward)
     Access: 2006-08-16 15:49:58.000000000 -0600
     Modify: 2006-08-16 15:49:58.000000000 -0600
     Change: 2006-08-16 15:49:58.000000000 -0600

     harp:~ > ln -s foobar barfoo

     harp:~ > stat foobar
       File: `foobar'
       Size: 4096 Blocks: 8 IO Block: 4096 Directory
     Device: 306h/774d Inode: 278848 Links: 2
     Access: (0775/drwxrwxr-x) Uid: ( 447/ ahoward) Gid: ( 447/ ahoward)
     Access: 2006-08-16 15:49:58.000000000 -0600
     Modify: 2006-08-16 15:50:20.000000000 -0600
     Change: 2006-08-16 15:50:20.000000000 -0600

i can't even begin to tell you how many legacy perl scripts i've found with
this logic error in them - it's a really hard one to track down.

in any case it's a simple thing to read about so i'm not sure why it causes so
much confusion... there simply is no concept of file creation time in unix.

btw. my dirwatch directory event code works around this to a large degree for
certain situations.

regards.

-a

···

On Thu, 17 Aug 2006, Chad Perrin wrote:

That is, effectively, creation time (for a particular definition of file
creation). It returns the time at which the file's listing in the
information for the enclosing directory changed, which basically means when
it was created within that directory. Same difference. I do think the
letter C stands for "change" in this case, though, not only in Ruby docs,
but in POSIX standards as well.

--
to foster inner awareness, introspection, and reasoning is more efficient than
meditation and prayer.
- h.h. the 14th dali lama

Not to mention, on my Linux machine, just opening up a file and saving it changes all the times (access, modify, and change) to the same time. I'm sure that varies by OS, though.

-Justin

···

ara.t.howard@noaa.gov wrote:

On Thu, 17 Aug 2006, Chad Perrin wrote:

That is, effectively, creation time (for a particular definition of file
creation). It returns the time at which the file's listing in the
information for the enclosing directory changed, which basically means when
it was created within that directory. Same difference. I do think the
letter C stands for "change" in this case, though, not only in Ruby docs,
but in POSIX standards as well.

man 2 stat

...
       The field st_ctime is changed by writing or by setting inode informa-
       tion (i.e., owner, group, link count, mode, etc.).
...

it's change time and this isn't even really close to creation time for __any__
definition since operations like chmod, chowner, chgrp or linking to the file
all effect this timestamp. for example
<snip>