呃。如果你使用perl那么你真的不需要打电话find(1)
!如果您使用File::Findfind
模块,那么您可以在没有外部调用的情况下获得更好的结果。尝试这样的事情:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $dir = "/opt/exploit/dev/florian/scan-allied/working-dir/";
my $addresse ="751471" ;
my $ip = "126.108.216.254";
my $re = "shswitch_${addresse}_${ip}_\d+";
sub wanted {
/^$re$/ and -f $_ and print "$_\n";
}
find \&wanted, $dir;
这将打印所有匹配的文件。
您可以使用find2perl
实用程序将完整的find
命令行转换为wanted
函数!
为了
find2perl /opt/exploit/dev/florian/scan-allied/working-dir -type f -name \"shswitch_751471_126.108.216.254_${ip}_*\"
提供以下代码:
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/opt/exploit/dev/florian/scan-allied/working-dir');
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ &&
/^"shswitch_751471_126\.108\.216\.254__.*"\z/s
&& print("$name\n");
}