分类: IT业界
2011-06-28 17:34:14
1,找出某个目录下面以*.old结尾的文件
#!/usr/bin/perl -w
use strict;
use File::Find;
my $path = '/home/test/';
sub wanted {
if ( -f $File::Find::name ) {
if ( $File::Find::name =~ /\.old$/ ) {
print "$File::Find::name\n";
}
}
}
find( \&wanted, $path );
2,找出某个目录下面几天前的文件
my $path = '/home/test/';
opendir DH, $path or die "cannot chdir to $path : $!";
for my $file (readdir DH) {
next if $file eq "." or $file eq "..";
next if $file =~ /^\./;
if (time() - (stat($path.$file))[8] > (60*60*24*7)) {
print $path.$file."\n";
}
}
closedir DH;