Operating System - HP-UX
1833780 Members
2333 Online
110063 Solutions
New Discussion

How long since a file was accessed?

 
SOLVED
Go to solution
Neil Edwards
Advisor

How long since a file was accessed?

Hello everyone,

I am working on a script to determine how long it has been since a file has been accessed. I have used "ls -lu filename" but that output is difficult to work with. Find only works over ranges of days but I need to know with better detail than that. Anyone know an easier method than ls -lu?

TIA, Neil
It wasn't me.
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How long since a file was accessed?

Hi Neil:

This is not too difficult and I already had a Perl script that was very close. I simply modified it with a '-e' argument to output epoch seconds. Try this:

FNAME=$1
shift
NOW=$(perl -e 'print time')
ACCESS_TIME=$(fileage.pl -a -e ${FNAME})
SECONDS=$(( ${NOW} - ${ACCESS_TIME) ))
echo "File ${FNAME} was last accessed ${SECONDS} ago."

You can, of course, divide ${SECONDS} into any other convenient unit of time.

Fileage.pl has quite a few other uses. Fileage.pl -u will give full usage.

Regards, Clay
If it ain't broke, I can fix that.
Neil Edwards
Advisor

Re: How long since a file was accessed?

Thanks Clay. That was perfect!!!

It wasn't me.