Skip to content

Instantly share code, notes, and snippets.

@torbiak
Created February 3, 2017 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torbiak/faf13507f1cd4dc9bfe8c08f50d46044 to your computer and use it in GitHub Desktop.
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
#!/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