[英]How to use Perl's File::Find::Rule module to find files with 777 perms
I want to use perl File::Find::Rule in order to find files in the server that have perms 777 我想使用perl File :: Find :: Rule来查找服务器中有perms 777的文件
I know that the module has stats tests so i could simply do this: 我知道该模块有统计测试,所以我可以这样做:
$rule->mode(33279)
I found the 33279 by creating a file and printing the permission on it assuming that File::Find::Rule takes decimal? 我发现33279是通过创建一个文件并打印它的权限,假设File :: Find :: Rule需要十进制? or should it be formatted somehow?
或者它应该以某种方式格式化?
Is this the right approach to have all the file that have exactly the 777 permissions? 这是使所有文件具有777权限的正确方法吗?
this is a script that finds all files on the home dir of a test server.. i want to change it so that it only finds those with 777 permissions. 这是一个脚本,可以找到测试服务器主目录上的所有文件。我想更改它,以便它只能找到具有777权限的文件。
#!/usr/bin/perl
use strict;
use warnings;
use File::Find::Rule;
my $rule = File::Find::Rule->new;
$rule->file;
$rule->name( '*' );
my @files = $rule->in( "/root" );
for my $file (@files) {
my $mode = (stat $file)[2];
printf ("%04o %s\n",$mode & 07777, $file);
}
The mode
includes the file permissions and type . 该
mode
包括文件权限和类型 。 You need to mask it so that you only get the permission bits. 您需要屏蔽它,以便只获取权限位。 Personally I'd implement a custom rule:
就个人而言,我实现了一个自定义规则:
use warnings;
use strict;
use File::stat;
use Fcntl qw/S_IMODE/;
use File::Find::Rule 'rule';
my $rule = rule->file->exec(sub{ S_IMODE(stat($_[2])->mode)==0777 });
my @files = $rule->in('/root');
for my $file (@files) {
print $file, "\n";
}
Note that this masked mode still includes the setuid/setgid/sticky bits (often known as Xst
). 请注意,此屏蔽模式仍包含setuid / setgid / sticky位(通常称为
Xst
)。 If you want to ignore those too, and check only the ugo
/ rwx
bits, then you'd have to mask against 0777
(eg $mode & 0777
). 如果你也想忽略它们,并只检查
ugo
/ rwx
位,那么你必须屏蔽0777
(例如$mode & 0777
)。
使用File::Find::Rule
很酷,但你可以通过find
轻松完成并在perl中获得答案:
@files = split /\n/, `/bin/find /root -perm 777`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.