1832089 Members
2708 Online
110037 Solutions
New Discussion

How old is a file ?

 
baiju_3
Esteemed Contributor

How old is a file ?

Dear All,

How to show , how "old" is a file is in minutes.

Thanks for your Answers ,
Regards ..BL.
Good things Just Got better (Plz,not stolen from advertisement -:) )
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: How old is a file ?

Hi:

# perl -le '$t=(stat $ARGV[0])[9];print time()-$t' filename

...gives a file age in seconds

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: How old is a file ?

Hi (again):

Oh, sorry, if you want minutes:

# perl -wle '$t=(stat $ARGV[0])[9];printf "%d\n",((time()-$t)/60)' filename

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: How old is a file ?

No matter what you are told, this is not possible. UNIX has no notion of the creation time of a file. If you know this, you only know it by accident. What you can know is how long since a file has been modified, changed, or accessed. The attached Perl script will do that:

fileage.pl -S myfile

will return the number of seconds since myfile was modified; divide by 60 and you havbe minutes. Invokew as fileage.pl without arguments for a usage display.

This script makes use of Perl's stat function.
If it ain't broke, I can fix that.
Hein van den Heuvel
Honored Contributor

Re: How old is a file ?

An alternative to the 'stat' function in perl is to use a filetest unary operator.

The same caveat about creation time exists of course. Thus it is missing from the list:

-M Script start time minus file modification time, in days.
-A Same for access time.
-C Same for inode change time (Unix, may differ for other platforms)


Sample usage to print file last modify time in minutes:

perl -e "print ((-M shift @ARGV) * 24 * 60)" file.dat


fwiw,
Hein.


Geoff Wild
Honored Contributor

Re: How old is a file ?

Sometimes, on binary files, doing a what will give you version and date info as to when the file was created.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.