Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created November 1, 2013 20:36
Show Gist options
  • Save waffle2k/7271562 to your computer and use it in GitHub Desktop.
Save waffle2k/7271562 to your computer and use it in GitHub Desktop.
A simple little Perl script that takes an epoch, and a regular expression that captures an epoch within a filename, then deletes said file.
#!/usr/bin/perl
use strict;
use Getopt::Long;
$|++;
my ( $cutoff, $re );
GetOptions (
"regex=s" => \$re,
"epoch=i" => \$cutoff,
) or die "Invalid arguments: $!";
die 'invalid epoch' unless ( $cutoff =~ /^\d+$/ );
while( <> ){
chomp;
if( $re and /$re/o and $1 < $cutoff and -e $_ ){
print "$_\n" and unlink $_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment