1752778 Members
5857 Online
108789 Solutions
New Discussion юеВ

Re: Change time change?

 
SOLVED
Go to solution
Chad Holcutt
Occasional Contributor

Change time change?

Hi,

I am very confused. I am updating a file inside a
Perl program and both the file change time and the modification time are being updated. I thought the change time was only supposed to change when the permissions or owner were changed.

Thanks,
Chad
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Change time change?

This is one of those "it depends" answers. If you update (specifically a write() system call) does not affect the length of the file then only the modification time is changed BUT if (as I suspect) the write is actually an append then the length of the file is changed and that is considered a "change" as well as a "modification".
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Change time change?

Oh, and don't blame me. I don
't make the UNIX rules and this one is pretty dumb.
If it ain't broke, I can fix that.
Chad Holcutt
Occasional Contributor

Re: Change time change?

Hi A. Clay

Thanks. That explains it. I was hoping to be able to use the change time as a creation time since I never was going to change the ownership or permissions of the files. Any ideas on how to capture the creation time of a file?

Thanks,
Chad
A. Clay Stephenson
Acclaimed Contributor

Re: Change time change?

1) Choose another OS. UNIX has no notion of a creation time of a file (although you seem to know this already).

II) Get used to disappointment. See 1) above.

C) Use another file to record the creation time of the file that you are interested in.

Four) Use your convention but preallocate the file so that the length doesn't change. However, one chmod or chown and see 1) above.
------------------------------------------
The least evil of these is C) --- although it isn't foolproof. You might adopt a convention such that myfile.data is matched to myfile.ts (for timestamp).
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Change time change?

Hi Chad:

Unis doesn't track a true creation time. When a file is first entered into a directory, its 'mtime' (modification) timestamp represents a creation time. As long as the file remains unmodified (metadata aside, as reflected in the 'ctime') then you can consider the 'mtime' to be a creation timestamp. However, any data change updates the 'mtime', obliterating the moment of creation. See the 'stat(2)' manpages for more information.

Beware that many backup utilities reset a file's last accesstime ('atime'). One such is 'fbackup'. While this is a seperate timestamp from the 'mtime', resetting the 'atime' *does* change the 'ctime'. Thus, it becomes virtually impossible, other than by documentation or tracking in your own database, to track anything like a creation timestamp in Unix.

Regards!

...JRF...

Regards!

...JRF...