使用 find 命令搜索可执行文件 [英] Search for executable files using find command
问题描述
我可以在 Unix find
命令中使用什么类型的参数/标志来搜索可执行文件?
What type of parameter/flag can I use with the Unix find
command so that I search executables?
推荐答案
在 GNU 版本的 find 你可以使用 -executable
:
On GNU versions of find you can use -executable
:
find . -type f -executable -print
对于 BSD 版本的 find,你可以使用 -perm
和 +
和一个八进制掩码:
For BSD versions of find, you can use -perm
with +
and an octal mask:
find . -type f -perm +111 -print
在此上下文中,+"表示设置了这些位中的任何一个",而 111 是执行位.
In this context "+" means "any of these bits are set" and 111 is the execute bits.
请注意,这与 GNU find 中的 -executable
谓词不同.具体来说,-executable
测试文件是否可以被当前用户执行,而-perm +111
只是测试是否设置了执行权限.
Note that this is not identical to the -executable
predicate in GNU find. In particular, -executable
tests that the file can be executed by the current user, while -perm +111
just tests if any execute permissions are set.
旧版本的 GNU find 也支持 -perm +111
语法,但从 4.5.12 不再支持此语法.相反,您可以使用 -perm/111
来获得此行为.
Older versions of GNU find also support the -perm +111
syntax, but as of 4.5.12 this syntax is no longer supported. Instead, you can use -perm /111
to get this behavior.
这篇关于使用 find 命令搜索可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!