For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2005 > delete file after on week









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author delete file after on week
Bing Zhao

2005-10-23, 3:56 am

Hi:
I need to delete files older than one w old, I know how to code that(with the help
of many kind people on this list):
But it only happens when I run the program, there is a chance I will not be running
the program for more than a w. And the dir keeps getting larger(downloading files from
website), I need those files older than 1 w all gone WITHOUT having to type ./do_it.pl on unix
command line.
Any idea on this? It seems pretty unreasonle to me, even. Let me know if this is
something impossible.
thank you.

bing
Jessica Rasku

2005-10-23, 3:56 am

ZHAO, BING wrote:
> Hi:
> I need to delete files older than one w old, I know how
> to code that(with the help of many kind people on this list):
> But it only happens when I run the program, there is a
> chance I will not be running the program for more than a w. And the
> dir keeps getting larger(downloading files from website), I need those
> files older than 1 w all gone WITHOUT having to type ./do_it.pl on
> unix command line.
> Any idea on this? It seems pretty unreasonle to me, even.
> Let me know if this is something impossible.
> thank you.


You can do this with a cron job. This is done frequently to keep things
up to date on your system. You can set it up to run things from
anywhere from every minute, to once a year (I think that's the limit of
the scope of the cron time fields, I don't believe there is a year
field). You will want to look at the cron and crontab man pages.

Jessica
José Pedro Silva Pinto

2005-10-24, 7:55 am

Hi, ZHAO,

If your system is Unix or similar, you can use cron (See cron). If =
Windows, you can use task manager

Jos=E9 Pinto

-----Original Message-----
From: ZHAO, BING [mailto:littleshrimp@berkeley.edu]=20
Sent: domingo, 23 de Outubro de 2005 7:28
Cc: beginners@perl.org
Subject: delete file after on w

Hi:
I need to delete files older than one w old, I know how =
to code that(with the help=20
of many kind people on this list):
But it only happens when I run the program, there is a =
chance I will not be running=20
the program for more than a w. And the dir keeps getting =
larger(downloading files from=20
website), I need those files older than 1 w all gone WITHOUT having =
to type ./do_it.pl on unix=20
command line.
Any idea on this? It seems pretty unreasonle to me, even. =
Let me know if this is=20
something impossible.
thank you.

bing

--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Steve Bertrand

2005-10-24, 6:56 pm


> I need to delete files older than one w old,
> I know how to code that(with the help of many kind people on
> this list):


Here is a single command that will blow files older than 48 hours away
from given directory. You can put as many of these in a single sh script
as you want, then put it in your crontab:

# find /home/me/mydirectory -mtime +48h -type f | xargs rm

Your crontab entry might look like this:

20 22 * * * /home/steve/scripts/rmmail.pl

Which would run the script at 10:20 PM, every day.

HTH,

Steve

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com