Created
May 18, 2017 04:44
-
-
Save allenday/57231d2612bcee36d0e661315b7de98f to your computer and use it in GitHub Desktop.
multiply the stat ctime value of a directory of files
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/perl | |
use strict; | |
use Time::HiRes; | |
my $rat = shift @ARGV; | |
my $dir = shift @ARGV; | |
$rat ||= 1; | |
-d $dir or die "$0 <ratio> <dir>"; | |
my @files = `find $dir -type f`; | |
my %f = (); | |
my $min_time = 999_999_999_999; | |
my $max_time = -1; | |
foreach my $file ( @files ) { | |
chomp $file; | |
my @stat = Time::HiRes::stat( $file ); | |
my $ctime = $stat[10]; | |
$f{ $file } = $ctime; | |
$min_time = $min_time < $ctime ? $min_time : $ctime; | |
$max_time = $max_time > $ctime ? $max_time : $ctime; | |
} | |
my $dur_time = $max_time - $min_time; | |
foreach my $file ( sort {$f{$a}<=>$f{$b}} keys %f ) { | |
my $rel_time = $f{ $file } - $min_time; | |
my $new_time = $rel_time * $rat; | |
print $new_time, "\t", $file, "\n"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment