Question: My webapp is hosted on a unix server using MySQL as database.

I wrote a Perl script to run backup of my database. The Perl script is inside the *cgi-bin* folde and it is working. I only need to set the cronjob and run the Perl script once a day.

The backups are stored in a folder named *db\_backups*,. However, I also want to add a command inside my Perl script to remove any files inside the folder *db\_backups* that are older than say 10 days ago.

I have searched high and low for unix commands and cannot find anything that matches what I needed.

Answer: 
`if (-M $file > 10) { unlink $file }`

or, coupled with `File::Find::Rule`

```
my $ten_days_ago = time() - 10 * 86400;
my @to_delete = File::Find::Rule->file()
  ->mtime("<=$ten_days_ago")
  ->in("/path/to/db_backup");
unlink @to_delete;

```
> 
> *i have searched high and low for unix commands
>  and cannot find anything that matches what i needed.*
> 
> 
> 

Check out [`find(1)`](http://linux.die.net/man/1/find) and [`xargs(1)`](http://linux.die.net/man/1/xargs). Warning: these commands may change your life at the shell prompt.

```
$ find /path/to/backup -type f -mtime +10 -print0 | xargs -0 echo rm -f

```

When you're confident that will Do What You Want (tm), remove the `echo`. It says, roughly, starting in `/path/to/backup`, descend looking for plain files whose *mtime* is greater than 10 days, and print their names to `xargs`, which will pass those names to `rm` in batches.

(`print0` and its complement `-0` are GNU extensions -- you mentioned you were on Linux -- which let you deal with whitespace in filenames safely.)