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

I am trying to test a file to see when it was created and when was the last time it was accessed. Can you help me? Perldocs does not help me I tried.
  • Comment on How can I test a file to find out when it was created

Replies are listed 'Best First'.
Re: How can I test a file to find out when it was created
by davorg (Chancellor) on Oct 02, 2002 at 08:21 UTC

    Unix has three file modification times for a file. None of them really register when a file was created. They are:

    • The last modification time
    • The last access time
    • The time the inode was last changed (this is probably closest in meaning to "creation time")

    You can access these values using stat or thefile test operators (specifically -M, -A and -C).

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      The time the inode was last changed (this is probably closest in meaning to "creation time"
      Considering that the inode changes even if you change the access rights, I wouldn't make that claim.

      Abigail

Re: How can I test a file to find out when it was created
by Abigail-II (Bishop) on Oct 02, 2002 at 09:46 UTC
    On Unix systems, you cannot. "File creation" time isn't a useful concept. How would you define it? What would happen if you move a file? Create a link? Remove a link? Remove all the content? Change all the content?

    Abigail

Re: How can I test a file to find out when it was created
by hotshot (Prior) on Oct 02, 2002 at 07:29 UTC

      stat will tell you the last modified time - mtime - without a problem, however it's not possible to tell (on most/all platforms) when a file was created - only the last time it's inode was modified - ctime.

      You might also find the standard File::stat module of use - it allows name based access to the various bits of info that stat returns.

      Cheers

      BazB