Operating System - HP-UX
1831372 Members
3424 Online
110024 Solutions
New Discussion

Modification time and creation time

 
SOLVED
Go to solution
Fred Ruffet
Honored Contributor

Modification time and creation time

Hi all !

Is there a way to display creation time on HP-UX ?

I must display the three different times of a file.

I use the perl stat function. It happens that modification and creation time are always the same.

If I use "ls -l" and "ls -lu", I can see access and modification date, but not creation.

It seems to me like creation time is not really stored.

Fred
--

"Reality is just a point of view." (P. K. D.)
11 REPLIES 11
Navin Bhat_2
Trusted Contributor

Re: Modification time and creation time

fsdb has a field called ctime. That can be the creation time but not always. If the inode has changed like by chown etc then ctime will get altered.
Jeff Schussele
Honored Contributor
Solution

Re: Modification time and creation time

Hi Fred,

Nope - absolute creation time is not stored.
There's no way to know this for sure.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Sundar_7
Honored Contributor

Re: Modification time and creation time

"ls -lc" it will tell you the last INODE modification time which could be identifical to the creation time (this is most unlikely).

Remember any syscall that modifies the inode meta data will effect the time shown by "ls -lc" - I would be curious to know if there is a way.
Learn What to do ,How to do and more importantly When to do ?
Rodney Hills
Honored Contributor

Re: Modification time and creation time

As stated before, their is no creation time.

The 3 time fields defined in a file inode are-

ctime inode change date/time (ie chmod file)
mtime data content change of file (ie vi file)
atime data content read of file (ie cat file)

HTH

-- Rod Hills
There be dragons...
Fred Ruffet
Honored Contributor

Re: Modification time and creation time

Thanks for all replies !

Rodney,

I do not agree with one point :
vi changes the creation time. Try it, and see. That's exactly what confused me. I thought that was because of vi edits a copy of the file, but if you do :
echo >> myfile
creation date is also changed, whereas it should absolutly not (inode is not touched).

If you want another example : /etc/passwd. I imagine that creation time shouldn't be equal to modification time, but...

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
A. Clay Stephenson
Acclaimed Contributor

Re: Modification time and creation time

Sorry Fred, in UNIX there is no such thing as creation time; that metadata are simply not stored in the inode. There are 3 times fields --- all specified in seconds since 00:00:00 1-Jan-1970 UTC. 1) Mtime - time of last modification of the CONTENTS of a file 2) Atime - time of last access 3) Ctime --- time of last change of mode, owner, or group.

Ctime is absolutely, positively not creation time; there just ain't no such animal. If any one of these 3 fields happens to coincide with the actual time the file was created, it's just that, coincidence.
If it ain't broke, I can fix that.
Fred Ruffet
Honored Contributor

Re: Modification time and creation time

Clay,

So if I understand, when I issue
echo >> myfile
ctime is changed cause opening and writing the file are issuing adjustments on the permissions (even if I am already owner).

So ctime and mtime will only be different after a chmod, chowner...

It's always a pleasure to have an answer from you.

Best regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Navin Bhat_2
Trusted Contributor

Re: Modification time and creation time

Hello Fred,
I think this is a known issue with 11.11 (PHCO_28530) and 11.23 where the st_ctime is changed because utime gets called. I tested this using the touch command. The behaviour is the same. I shall try this on a 11.00 system too. And also try after installing PHCO_28530.

Rgds
A. Clay Stephenson
Acclaimed Contributor

Re: Modification time and creation time

Okay do this:

echo "XXX" > myfile

ls -l myfile (modification time)
ls -lc myfile (change time)
ls -lu myfile (access time)

wait about 2 minutes

echo "YYY" >> myfile
and repeat the 3 ls commands

wait about 2 more minutes

chmod 640 myfile
ls -l myfile (mtime)
ls -lc myfile (ctime)

Again, if you happen to know the time a file was created, it's only accidental.

If it ain't broke, I can fix that.
Fred Ruffet
Honored Contributor

Re: Modification time and creation time

> Again, if you happen to know the time a file was created, it's only accidental.

I understand and agree with that. Also your test runs fine, and I have the three times different.
What confused me was just that if you invert the two last (first chmod, then >>), you will have ctime=mtime. (but due to your precedent post, it's clear to me)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Navin Bhat_2
Trusted Contributor

Re: Modification time and creation time

The reason echo "something" >> to_a_file will alter the ctime is because the inode information for EOF changes.

The touch(1) manpage documents the following:

DESCRIPTION
touch updates the access, modification, and last-change times of each
argument.

For vi, it makes changes into a tmp file until the file is saved, when it then removes the old file and renames the tmp file to the old name.

Hope this clarifies why ctime is updated.