Created
February 3, 2017 03:33
-
-
Save torbiak/faf13507f1cd4dc9bfe8c08f50d46044 to your computer and use it in GitHub Desktop.
Print the group of files modified within an hour of the most recently modified file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Print the group of files modified within an hour of the most recently | |
# modified file. | |
use strict; | |
use List::Util qw[min max]; | |
use Getopt::Std; | |
$Getopt::Std::STANDARD_HELP_VERSION = 1; | |
sub HELP_MESSAGE { | |
my $out = shift; | |
print $out "usage: mrmgroup [-H HOURS] FILE...\n" | |
} | |
sub VERSION_MESSAGE { | |
} | |
my %opts = ("H", 1); | |
getopts('hH:', \%opts); | |
if ($opts{h}) { | |
my $stdout = *STDOUT; | |
HELP_MESSAGE($stdout); | |
exit(0); | |
} | |
my $delta = $opts{"H"} * 3600; | |
my %times; | |
for my $f (@ARGV) { | |
my @s = stat $f; | |
$times{$f} = $s[9]; | |
} | |
my $latest = max(values(%times)); | |
for my $f (keys %times) { | |
my $mtime = $times{$f}; | |
if ($latest - $mtime < $delta) { | |
print $f . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment