Linux chmod:如何仅向已具有执行权限的文件递归添加执行权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6937885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:27:32  来源:igfitidea点击:

chmod: How to recursively add execute permissions only to files which already have execute permission

linuxunixshellchmod

提问by Clinton

I noticed:

我注意到:

chmod -R a+xadds execute permissions to all files, not just those who are currently executable.

chmod -R a+x为所有文件添加执行权限,而不仅仅是那些当前可执行的文件。

Is there a way to add execute permissions only to those files who already have an execute set for the user permission?

有没有办法只向那些已经为用户权限设置执行集的文件添加执行权限?

采纳答案by Oliver Charlesworth

Use find:

使用find

find . -perm /u+x -execdir chmod a+x {} \;

回答by Reto Aebersold

You can use find to get all those files:

您可以使用 find 来获取所有这些文件:

find . -type f -perm -o+rx -print0 | xargs -0 chmod a+x

Update: add -print0 to preserve space in filenames

更新:添加 -print0 以保留文件名中的空间