Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Please explain -C / inode

by Elliott (Pilgrim)
on Jul 01, 2002 at 21:36 UTC ( [id://178691]=perlquestion: print w/replies, xml ) Need Help??

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

According to the Camel Book, -C$filename gives the age of the file in days since the last inode change. Can someone please tell me what that means!?

Specifically, can I use -C to tell me when a file was first created even if it has been overwritten since? (I assume so, since otherwise what would be the difference with -M?) Does it make any difference HOW it was overwritten?

Replies are listed 'Best First'.
Re: Please explain -C / inode
by emilford (Friar) on Jul 01, 2002 at 22:00 UTC
    I believe the -C option relative to a filename represents the ctime of the inode. Don't ask me what this means, I'm just reading about it in a book (Perl Cookbook). I've read far enough to get to the following line: "The ctime is not the creation time; there is NO way under standard UNIX to find a file's creation time." Bummer since that is what I think you're trying to do. I'm not saying that it can't be done from personal experience, I'm just stating what was in the book! Below is a brief explanation as stated in the Perl Cookbook.

    An inode (index-node) is an entry in the index that are relative to a set of data blocks. The inode is a flat file and is addressed by number. An inode acts as a pointer to a specific set of data blocks, but also contains information on the type of things it represents (directory, plain file, etc).

    The inode contains many fields, but of relevance to this post: atime, ctime, and mtime.

    atime - updated every time pointer to the file's data blocks is followed and the file's data is read

    ctime - updated each time the file's inode changes

    mtime - updated each time the file's data changes

    You might also want to read up about File::Stat, which provides an interface to all of these values. It's a very effective method of obtaining information about a certain file.

    HTH, Eric
      Thank you for this info. It seems fairly clear that if I want a creation date, I'll have to write it myself somewhere. (Just wish I'd thought of it BEFORE I created the files :-)

      My fundamental question is now answered but I am still curious... what on earth is -C for?
        The -C is the operator for the ctime stat field. They (-C and ctime) both mean the file's (inode) change time. I can't explain it any further. Perhaps one of the other monks?

        what on earth is -C for?

        "The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.)." -- stat(2)

        Next time, maybe you should try Google first.

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

Re: Please explain -C / inode
by perigeeV (Hermit) on Jul 02, 2002 at 11:02 UTC

    The touch utility has a good explanation:

    Although touch provides options for changing two of the times -- the times of last access and modification -- of a file, there is actually a third one as well: 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. One common example of this is when the permissions of a file change. Changing the permissions doesn't access the file, so the atime doesn't change, nor does it modify the file, so the mtime doesn't change. Yet, something about the file itself has changed, and this must be noted somewhere. This is the job of the ctime field. This is necessary, so that, for example, a backup program can make a fresh copy of the file, including the new permissions value. Another operation that modifies a file's ctime without affecting the others is renaming. In any case, it is not possible, in normal operations, for a user to change the ctime field to a user-specified value.

    Hope that helps.


A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-24 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found