Solved

delete files periodically

Posted on 2000-04-28
3
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
monas earned 20 total points
ID: 2759086
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
ID: 2760297
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
ID: 2761838
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

628 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