Operating System - HP-UX
1846965 Members
4455 Online
110257 Solutions
New Discussion

Has a file been read in the last 30 seconds?

 
SOLVED
Go to solution
Derek Card
Advisor

Has a file been read in the last 30 seconds?

Hello Forumers,

Is there a way in UNIX to find out if a file has been read in the last 30 seconds? Find -atime seems to only work numbers of days.

TIA, Derek
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Has a file been read in the last 30 seconds?

Well you could use find -newer tv1 tv2 filename to do this after creating a reference file with touch. Man find for details.

Plan B: Use the attached Perl script.

fileage.pl -a -s 30 myfile
STAT=${?}
if [ ${STAT} -eq 1 ]
then
echo "File has been accessed in the last 30 seconds"
fi

That should do it for you; fileage.pl -u will give full usage.


If it ain't broke, I can fix that.
Derek Card
Advisor

Re: Has a file been read in the last 30 seconds?

Thanks Clay. Your perl program works great. I can even use the -c option to find out how long it's been since a file was created. I did add the -v option so that the result was actually printed.

Thank you, Derek
A. Clay Stephenson
Acclaimed Contributor

Re: Has a file been read in the last 30 seconds?

Hi Derek:

I'm glad yoy liked the script BUT you can't use the -c option (or find's -ctime) to determine when a file was created. Actually, you can in a few cases but that is by accident. A file's ctime does NOT mean creation but rather changed (not the same as modified). It means the time since a file was chmod'ed or chown'ed or chgrp'ed ... . Surprisingly, there is no way in UNIX to know when a file was actually created. The inode simply does not carry that data.

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