linux - 运行 Perl 脚本时意外锁定了文件夹

标签 linux perl chmod

我有一个包含以下代码的 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/

相关文章:

c++ - CMake 链接到错误版本的库

linux - SQLite:Fsyncing with journal_mode = wal and synchronous = normal

linux - 合并头文件和部分尾文件然后合并到标准输出的有效方法

python - Linux。 Heroku-Django。 Collectstatic 只读文件系统

macos -/usr/bin/ssh-copy-id: line 1: ucgi::command not found

linux - 如何在Centos上安装ssh2?

linux - GUI 中的数百万行

perl - 如何检查 unix 时间早了 1 天

linux - 如何根据第一个字段合并csv文件中的记录?

ruby-on-rails - Rails 3.1 Assets :precompile rake aborted! 权限被拒绝?