Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Deleting old files using stat

0 views
Skip to first unread message

Bill H

unread,
Jun 13, 2008, 9:57:54 PM6/13/08
to
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

Ben Morrow

unread,
Jun 13, 2008, 11:20:44 PM6/13/08
to

Quoth Bill H <bi...@ts1000.us>:

> 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

--
Although few may originate a policy, we are all able to judge it.
Pericles of Athens, c.430 B.C.
b...@morrow.me.uk

Bill H

unread,
Jun 14, 2008, 4:24:47 AM6/14/08
to
On Jun 13, 11:20 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Bill H <b...@ts1000.us>:

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

0 new messages