Operating System - HP-UX
1832592 Members
2618 Online
110043 Solutions
New Discussion

Re: How long (in seconds) since a file has been modified?

 
SOLVED
Go to solution
Kris Spander
Advisor

How long (in seconds) since a file has been modified?

Hello,

Anybody know a way to tell how long ago a file was modified. The ls -l output is very cumbersome.

TIA,
Kris
Dilbert is my hero.
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How long (in seconds) since a file has been modified?

The key to your problem is a combination of the perl time() function - which yields the current epoch seconds and the stat() function. The difference between time() and stat()'s mtime value is your boy - OR - you can simply use this Perl program.

fileage.pl -S myfile

The time since last modification will be output in seconds.

That should fix you, Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: How long (in seconds) since a file has been modified?

Ooops, I should have mentioned "invoke as fileage.pl -u for full usage." It will also optionally look at the last access or last change times.

If it ain't broke, I can fix that.
Kris Spander
Advisor

Re: How long (in seconds) since a file has been modified?

Thanks. That was perfect :-)


Dilbert is my hero.
H.Merijn Brand (procura
Honored Contributor

Re: How long (in seconds) since a file has been modified?

Or simply

# perl -le'print 86400*-M shift' file

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: How long (in seconds) since a file has been modified?

Clay and Kris, to explain above (which is both easier and faster than stat): -M give the age of the file in days (and fractions of days) to the time the script started (also available and $^T). A day has 86400 seconds (24*60*60), so 86400*-M file is the age of the file in seconds to the time the script started (now).

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn