设置文件权限所需的 perl chmod 帮助
下面是我的代码:
foreach my $node (@switch_list) {
chomp $node;
print "$node \n";
my $f3 = ">$node.txt";
chmod 0755, $f3;
open FILE3, "$f3" or die "Could not open file:$! \n";
}
这里我想创建许多具有完全权限的文件,但似乎使用创建的文件 权限:0640 而不是 0755。
Below is my code:
foreach my $node (@switch_list) {
chomp $node;
print "$node \n";
my $f3 = ">$node.txt";
chmod 0755, $f3;
open FILE3, "$f3" or die "Could not open file:$! \n";
}
Here I want to create many files with full permission but it seems that file created with
permission: 0640 and not 0755.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在做的事情:
因此 Perl 查找名为
>$node.txt
的文件。相反,做:
You are doing:
So Perl looks for a file named
>$node.txt
.Instead do:
codaddict 是正确的,因为您已将模式包含在
$f3
字符串中,这可能会使chmod
失败。但是,比使用 chmod 更好的解决方案可能是使用
umask
,我相信它可以与open
一起使用(尽管文档只特别提到sysopen
,而且我不在 Linux 中,所以我可以尝试一下出去)。codaddict are correct in that you have included the mode in your
$f3
string, which probably makeschmod
fail.However, a better solution than to use
chmod
might be to useumask
, which I believe works withopen
(although the documentation only specifically mentionssysopen
, and I am not in linux so I can try it out).