For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2005 > how to get file's creation time









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to get file's creation time
Jennifer Garner

2005-11-28, 3:55 am


hi,

How to get file's creation time,NOT last modify time?Thanks.

usenet@DavidFilmer.com

2005-11-28, 3:55 am

Jennifer Garner wrote:
> hi,
>
> How to get file's creation time,NOT last modify time?Thanks.


You can't. A file has a block of data called an "inode" which contains
certain pieces of information, such as the last modification time (and
group/owner, file permissions, etc). But the inode does not have a
field for file creation time (the "ctime" field does not refer to the
creation time; it refers to the time that the status of the file was
last modified).

Sorry, it's not possible to extract the creation time from a file. If
the file was created by a process that keeps a logfile (such as a
webserver) you may be able to infer the creation time by parsing the
application logs, but you can't get the information from the file
itself.

Wijaya Edward

2005-11-28, 3:55 am




----- Original Message -----
From: Jennifer Garner <JenGarner@30gigs.com>
Date: Monday, November 28, 2005 12:30 pm
Subject: how to get file's creation time


> How to get file's creation time,NOT last modify time?Thanks.


I don't think it is possible, in unix environment.

Read this comment by Randall Schwartz,
http://www.perlmonks.org/index.pl?node_id=479799

Hope it gives you a hint ...

---
Regards,
Edward WIJAYA
SINGAPORE


--------------------------------------------------
This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you.
--------------------------------------------------
Randal L. Schwartz

2005-11-28, 6:57 pm

>>>>> "Jay" == Jay Savage <daggerquill@gmail.com> writes:

Jay> It depends on what you mean by "creation". stat() on POSIXish systems
Jay> returns ctime, which is the inode creation time,

Nope. Inode *change* time. Will update any time you write to the
file, or change any metadata (owner, permissions, number of links
[including renaming], other timestamps).

Jay> which is the time the
Jay> physical location on disk was first written to (actually, these days
Jay> it's the time the vnode was fist written to, but you don't really care
Jay> that much about disk geometry, do you?). The time will not be
Jay> preserved across relocations (i.e. mv and cp will destroy it),
Jay> although many archivers reinstate the file's original ctime when files
Jay> are restored from backup.

This is not possible at a user-level. You can set atime and mtime from
a system call, but not ctime. ctime is always set to "now".

Jay> For most applications, though, "when this
Jay> particular disk space was reserved for data" is an effective synonym
Jay> for "when this file was created. When you start moving files around,
Jay> the questions merlyn raises become much more important.

Jay> For the record, Kirk McKusick--one of the original implemetors of
Jay> UFS/FFS and the creator of UFS2--tells the story a little differently.
Jay> According to him, the FFS originally intended to use ctime as the
Jay> creation time, but they discovered that dump needed a record of inode
Jay> creation to make incrimental backups effectively. In fact, UFS2
Jay> includes a btime (call it "birth time" if you want) field that is
Jay> stable across inode relocations when the system uses btime aware file
Jay> system operations. I don't know, though, if the Perl team has plans to
Jay> update stat() to support it on systems where it is available.

Jay> Of course, that isn't completely at odds with merlyn's comments: the
Jay> original unix developers started implementing file systems a decade
Jay> before Berkely started work on FFS.

And, the whole notion of "creation time" doesn't make sense in the
first place. If I add a word, is it a new file, or an old file? If I
gut the entire contents, replace it with entirely new contents, is it
new or old? What if I rename it? Is it new, or old? There are no
consistent answers to any of those questions, so why bother?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Jennifer Garner

2005-11-29, 7:56 am


Thanks for Schwartz and Jay.I have known something from your words.

On 28 Nov 2005 08:48:28 -0800, merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>
> Jay> It depends on what you mean by "creation". stat() on POSIXish systems
> Jay> returns ctime, which is the inode creation time,
>
> Nope. Inode *change* time. Will update any time you write to the
> file, or change any metadata (owner, permissions, number of links
> [including renaming], other timestamps).
>
> Jay> which is the time the
> Jay> physical location on disk was first written to (actually, these days
> Jay> it's the time the vnode was fist written to, but you don't really
> care
> Jay> that much about disk geometry, do you?). The time will not be
> Jay> preserved across relocations (i.e. mv and cp will destroy it),
> Jay> although many archivers reinstate the file's original ctime when
> files
> Jay> are restored from backup.
>
> This is not possible at a user-level. You can set atime and mtime from
> a system call, but not ctime. ctime is always set to "now".
>
> Jay> For most applications, though, "when this
> Jay> particular disk space was reserved for data" is an effective synonym
> Jay> for "when this file was created. When you start moving files around,
> Jay> the questions merlyn raises become much more important.
>
> Jay> For the record, Kirk McKusick--one of the original implemetors of
> Jay> UFS/FFS and the creator of UFS2--tells the story a little
> differently.
> Jay> According to him, the FFS originally intended to use ctime as the
> Jay> creation time, but they discovered that dump needed a record of inode
> Jay> creation to make incrimental backups effectively. In fact, UFS2
> Jay> includes a btime (call it "birth time" if you want) field that is
> Jay> stable across inode relocations when the system uses btime aware file
> Jay> system operations. I don't know, though, if the Perl team has plans
> to
> Jay> update stat() to support it on systems where it is available.
>
> Jay> Of course, that isn't completely at odds with merlyn's comments: the
> Jay> original unix developers started implementing file systems a decade
> Jay> before Berkely started work on FFS.
>
> And, the whole notion of "creation time" doesn't make sense in the
> first place. If I add a word, is it a new file, or an old file? If I
> gut the entire contents, replace it with entirely new contents, is it
> new or old? What if I rename it? Is it new, or old? There are no
> consistent answers to any of those questions, so why bother?
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
> 0095
> <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
> training!
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com