#!/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";
}
--结束END--
本文标题: Perl生成文件或者文件夹的权限、属主
本文链接: https://lsjlt.com/news/246046.html(转载时请注明来源链接)
有问题或投稿请发送至:
邮箱/279061341@qq.com QQ/279061341
0