delete files periodically

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?
Who is Participating?
monasConnect With a Mentor Commented:
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.
find2perl /directory/with/your/files -type f -mtime +2 -exec rm {} \;

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

require "";

# Traverse desired filesystems



sub wanted {
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _ &&
    (int(-M _) > 2) &&
    (unlink($_) || warn "$name: $!\n");
is it possible to use crontab or sth else that the program works automatically, no need i run the program many times?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.