Tuesday, November 4, 2014

How do you delete specific files older than 7 days in a directory?

foreach my $dir (@ARGV) {
foreach my $file ( grep { (-M) > 7 } glob("$dir/*.{log,zip}") ) {
print "\nRemoving - $file ...";
unlink $file;
}
}

Note:
It deletes all log/zip files in a directory.

No comments :