Solved

delete files periodically

Posted on 2000-04-28
3
163 Views
Last Modified: 2010-03-05
in one of my perl-cgi script, i create a file with random name when a user submit some information,
now there are more and more files,
i would like to delete some of them.

in my plan, i want to delete files of two days long automatically using a perl program.

can any one provide a script?
0
Comment
Question by:bighuen
3 Comments
 
LVL 3

Accepted Solution

by:
monas earned 20 total points
Comment Utility
You can do this from [unix] shell

find /directory/with/your/files -type f -mtime +2 -print|xargs rm

this will remove files in subdirectories also.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
find2perl /directory/with/your/files -type f -mtime +2 -exec rm {} \;
#!/usr/local/bin/perl

eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
        if $running_under_some_shell;

require "find.pl";

# Traverse desired filesystems

&find('/directory/with/your/files');

exit;

sub wanted {
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _ &&
    (int(-M _) > 2) &&
    (unlink($_) || warn "$name: $!\n");
}
0
 

Expert Comment

by:mwhuen
Comment Utility
is it possible to use crontab or sth else that the program works automatically, no need i run the program many times?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now