下面是整个过程的perl版本:
过滤器.pl
#!/usr/bin/perl
use strict;
use warnings;
use File::Spec;
# -------------------------- configuration ----------------------------
my %CFG = (
'propertiesFile' => 'somfile.properties',
'propertyKey' => 'SOMEPROPKEY',
'duCommand' => 'du -Bk -s'
);
# ---------------------------------------------------------------------
while (my $dir = <>) {
chomp $dir;
open(my $F, File::Spec->catfile($dir, $CFG{"propertiesFile"})) || next;
my ($match) = grep /$CFG{"propertyKey"}=\d+/, <$F>;
close $F;
if ($match =~ m/$CFG{"propertyKey"}=(\d+)/) {
my ($volume, $directories, $file) = File::Spec->splitpath($dir);
my $command = "$CFG{'duCommand'} $dir";
# on Windows you might need $volume this assumes Unix-like filesystem
print $directories . "," . $file . "," .
`$command | cut -f1` if $1 > time();
}
}
exit;
使用
find /home/regis/stackoverflow/2937940/* -maxdepth 0
-mtime -150 -type d | ./filter.pl
输出(带样品)
/home/regis/stackoverflow/2937940/,subfolder1,16K
/home/regis/stackoverflow/2937940/,subfolder2,16K
/home/regis/stackoverflow/2937940/,subfolder4,16K