我有一个包含以下代码的 Perl 脚本
#/usr/bin/perl
use strict; use warnings;
chmod -R 775,"path-to-current-folder";
运行此脚本后,我无法再访问当前文件夹(当然也无法打开此脚本)。在 Konqueror 中看到文件夹时,文件夹图标中有一个额外的锁。任何人都可以告诉我发生了什么以及我该如何撤消此操作?
我检查了这个文件夹的权限,显然它被更改为d----------
。我已经通过重置权限解决了这个问题,但如果有人能解释为什么会这样,那就太好了。谢谢。
最佳答案
我认为您将“chmod”shell 命令与“chmod”perl 函数混淆了。后者将单个列表作为参数,其第一个元素必须是以八进制表示的数字代码。来自 perldoc -f chmod
;
chmod LIST
Changes the permissions of a list of files. The first element
of the list must be the numeric mode, which should probably be
an octal number, and which definitely should not be a string of
octal digits: 0644 is okay, but "0644" is not. Returns the
number of files successfully changed. See also "oct" if all
you have is a string.
$cnt = chmod 0755, "foo", "bar";
chmod 0755, @executables;
... etc ...
前者 - 即 shell - 有一个 -R
开关。有关详细信息,请参见 man chmod
。
关于linux - 运行 Perl 脚本时意外锁定了文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36396679/