Perl生成文件或者文件夹的权限、属主
#!/usr/bin/perl
use strict;
use warnings;
##生成目录放到一个临时文件,然后根据这个文件生成权限。
##find /usr -type d -ls |awk '{print $11}' > test_dir.txt
my $filename = 'test_dir.txt';
open(my $fh, $filename) or die "Could not open file '$filename' $!";
while (my $row = <$fh>) {
chomp $row;
my $chmod_line=`stat $row|grep Uid|awk -F\'\(\' \'{print \$2\}\'|awk -F\/ \'{print \$1\}\'`;
my $user_name=`stat $row|grep Uid|awk -F'(' '{print \$3}'|awk -F\/ '{print \$2}'|awk -F')' '{print \$1}'`;
my $group_name=`stat $row|grep Uid|awk -F'/' '{print \$4}'|awk -F')' '{print \$1}'`;
chomp $chmod_line;
chomp $user_name;
chomp $group_name;
$user_name =~ s/^\s+|\s+$//g;
$group_name =~ s/^\s+|\s+$//g;
print "mkdir -p $row\n";
print "chmod $chmod_line $row \n";
print "chown $user_name:$group_name $row \n";
}
分享标题:Perl生成文件或者文件夹的权限、属主
分享地址:
http://dzwzjz.com/article/jcoodh.html