Perl更改目录路径的所有权

时间:2021-08-10 16:43:56

I am trying to change the ownership of the list of directory such that

我正在尝试更改目录列表的所有权

chown -LR deep:deep deep/list/of/50/subdirectories
chown -LR deep:deep deeps/list/of/50/subdirectories

But I am getting error for more than 10 sub directories. I thought of writing a perl script such that it is in the same folder as the deep and deeps level. I got to learn about File::path module in perl. But there are only make and rmtree functions in to. Please can somebody help regarding this problem. Thanks.

但我收到超过10个子目录的错误。我想过编写一个perl脚本,使它与深度和深度级别位于同一个文件夹中。我在perl中学习了File :: path模块。但是只有make和rmtree函数。有人可以帮忙解决这个问题。谢谢。

2 个解决方案

#1


1  

it sounds like you're running into the fact that Unix has a limit on the length of pathnames. If you're trying to access a deeply nested directory, the pathname will be too long.

听起来你正在遇到Unix对路径名长度有限制的事实。如果您尝试访问深度嵌套的目录,则路径名将太长。

You can get around this by cd'ing into each directory a few levels at a time:

您可以通过一次几个级别进入每个目录来解决这个问题:

( cd deep/list/of; cd some/more/levels; cd and/a/few/more; ...
  chown -LR deep:deep subdirectories )
( cd deeps/list/of; cd some/more/levels; cd and/a/few/more; ...
  chown -LR deep:deep subdirectories )

The parentheses are so that all the cd commands take place in a subshell; when it's done, you're returned to the original shell, starting in the same top-level directory, so you can then process the next subdirectory from there.

括号是这样的,所有cd命令都发生在子shell中;当它完成后,你将返回到原始shell,从同一个*目录开始,这样你就可以从那里处理下一个子目录。

The default limit on pathname size is in <limits.h>:

路径名大小的默认限制在 中:

#define PATH_MAX        4096    /* # chars in a path name including nul */

although individual filesystems may override this.

虽然单个文件系统可能会覆盖它。

#2


0  

If you want to do this in Perl, you'll have to walk the directories yourself, with something like File::Find. You can specify whether the code changes into the new directory (so the relative path is shorter).

如果你想在Perl中执行此操作,则必须自己遍历目录,例如File :: Find。您可以指定代码是否更改为新目录(因此相对路径更短)。

#1


1  

it sounds like you're running into the fact that Unix has a limit on the length of pathnames. If you're trying to access a deeply nested directory, the pathname will be too long.

听起来你正在遇到Unix对路径名长度有限制的事实。如果您尝试访问深度嵌套的目录,则路径名将太长。

You can get around this by cd'ing into each directory a few levels at a time:

您可以通过一次几个级别进入每个目录来解决这个问题:

( cd deep/list/of; cd some/more/levels; cd and/a/few/more; ...
  chown -LR deep:deep subdirectories )
( cd deeps/list/of; cd some/more/levels; cd and/a/few/more; ...
  chown -LR deep:deep subdirectories )

The parentheses are so that all the cd commands take place in a subshell; when it's done, you're returned to the original shell, starting in the same top-level directory, so you can then process the next subdirectory from there.

括号是这样的,所有cd命令都发生在子shell中;当它完成后,你将返回到原始shell,从同一个*目录开始,这样你就可以从那里处理下一个子目录。

The default limit on pathname size is in <limits.h>:

路径名大小的默认限制在 中:

#define PATH_MAX        4096    /* # chars in a path name including nul */

although individual filesystems may override this.

虽然单个文件系统可能会覆盖它。

#2


0  

If you want to do this in Perl, you'll have to walk the directories yourself, with something like File::Find. You can specify whether the code changes into the new directory (so the relative path is shorter).

如果你想在Perl中执行此操作,则必须自己遍历目录,例如File :: Find。您可以指定代码是否更改为新目录(因此相对路径更短)。