Deleting old files using stat

B

Bill H

I am thinking of using the "atime" (last access time in seconds since
the epoch) value returned by stat($filename) to find files (session
ids created by my program) that have not been accessed in 24 hours and
delete them.

But before I do this I thought I would ask if there was a better way
than itterating over all the files in a folder (could be 1000's of
them if the site is busy) and running stat on each and determining if
24 hours has passed?

The other question I had, if I do end up doing this, I should be able
to determine if 24 hours has passed if I subtract the atime from time
to get the number of seconds passed since it was last accessed,
correct?

Bill H
 
B

Ben Morrow

Quoth Bill H said:
I am thinking of using the "atime" (last access time in seconds since
the epoch) value returned by stat($filename) to find files (session
ids created by my program) that have not been accessed in 24 hours and
delete them.

But before I do this I thought I would ask if there was a better way
than itterating over all the files in a folder (could be 1000's of
them if the site is busy) and running stat on each and determining if
24 hours has passed?

Nope. About the only other option would be running some daemon that used
FAM or some other change-notify system to keep track of which files were
opened, but that would almost certainly be more expensive.
The other question I had, if I do end up doing this, I should be able
to determine if 24 hours has passed if I subtract the atime from time
to get the number of seconds passed since it was last accessed,
correct?

The -A operator is provided for exactly this sort of job.

Ben
 
B

Bill H

Nope. About the only other option would be running some daemon that used
FAM or some other change-notify system to keep track of which files were
opened, but that would almost certainly be more expensive.


The -A operator is provided for exactly this sort of job.

Ben

Thanks Ben. I wanted to ask to be sure. There has been a few times
where I have spent hours perfecting a routine only to find out that
there was a perl command I didnt know about that did the same thing

Bill H
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top