如何仅在目录上执行递归 chmod?

Wil*_*mKF 38 linux chmod

我想更改 Centos 4 上树的权限,以从目录递归地添加所有目录的执行权限。如果我使用普通的 chmod,目录以外的文件也会被修改:

chmod -R o+x /my/path/here
Run Code Online (Sandbox Code Playgroud)

我怎样才能只影响目录?

Dan*_*eck 57

与主要find-type d目录)上运行-execchmod对文件夹执行唯一的操作:

find /your/path/here -type d -exec chmod o+x {} \;
Run Code Online (Sandbox Code Playgroud)

为了确保它只在所需的对象上执行它,您可以先运行find /your/path/here -type d;它会简单地打印出它找到的目录。

  • @Srekel 看到这个答案 https://askubuntu.com/questions/339015/what-does-mean-in-a-linux-command (4认同)
  • 你能解释一下什么是 {} \; 做? (2认同)

小智 22

请参阅维基百科中的命令行示例 - chmod

# Remove the execute permission on all files in a directory 
# tree, while allowing for directory browsing.
chmod -R a-x+X directory    
                            
Run Code Online (Sandbox Code Playgroud)

正如丹尼尔补充的那样:这应该适用于您的情况:

chmod -R o+X directory
Run Code Online (Sandbox Code Playgroud)

  • 对于那些想知道区别的人,像我一样,X 将*也*将执行权限应用于已经设置了至少一个执行权限位的任何文件(用户、组或其他)。在一般情况下,接受的答案更好。 (4认同)
  • @scriptmonster 在这种情况下引用的行是错误的,但是`chmod -R o+X directory` 应该适用于 OP。 (2认同)