1833401 Members
4162 Online
110052 Solutions
New Discussion

Re: File creation times?

 
SOLVED
Go to solution
Robert Fisher_1
Frequent Advisor

File creation times?

Hello experts,

I have what i hope is a very simple question. How can I determine when a file was created?

TIA, Bob
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: File creation times?

You have a very simple question and I have a very simple answer: "You can't." (Or at least if you can, it's only by accident.) The file creation time is not carried in the inode but MAY be the same as the ctime (time mode, ownergroup, group was changed.).

Your only real, reliable option is to carry that data in the filename itself or as part of the file.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: File creation times?

Hi Bob:

There is no creation timestamp maintained. You can interrogate the 'modification' timestamp (which is equivalent to the creation one when the file is first created) with 'ls -l', but this timestamp changes if a file is opened and written to afterwards. The '-c' option of 'ls' tracks permission and ownership changes and the '-u' option of 'ls' offers the last-access timestamp.

Remember, any or all, of these timestamps can be manipulated with the 'touch' command. See the man pages for more information.

Regards!

...JRF...
Robert Fisher_1
Frequent Advisor

Re: File creation times?

Thanks Clay and JRF for the fast answers. Clay, you mentioned that I might include the creation time in the filename. How can I do that?
A. Clay Stephenson
Acclaimed Contributor

Re: File creation times?

Hi Bob:

Well you could use various options of the date commands output to record the timestamp as a filename suffix. e.g. myfile.YYYYMMDDHHMMSS or Plan B. simply use the epoch seconds to do this.

SECONDS=$(perl -e 'print time')

The inverse would be
perl -e "print scalar localtime(${SECONDS})".
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: File creation times?

via shell scripting...

forgive any errors, don't have a UX machine I can even look at today.

TIMESTAMP=`date`

FILENAME="Steves data file.%m%s%d.data"

...
create file using name


...
end of script.

There are dozens of options on exactly how you want to stamp the file. If my flu burned out neurons recall this information is in the documentaiton of the date command.

Someone correct or add on. I'm trying to get across a concept that needs to be in the thread, but I don't have a reference script here.

darn.

half a try.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com