我正在尝试使用Unix的find命令来计算某种类型的目录(即Solaris(MSB)可执行文件)中的可执行文件数。我知道我可以很容易地获得此目录中所有可执行文件的数量
find . -type f -perm -u+rx | wc -l
但是,这并不只计算Solaris(MSB)可执行文件。我想补救一下,我只会抛出一个-name
标志,像这样。
find . -name "sparc*" -type f -perm -u+rx | wc -l
只有当我删除命令中指定它们需要可执行的部分时,这才正确地返回6。如果我保留命令的这一部分,它将返回计数为0的“错误”。当我查看下面的ls -l
命令时,可以看到这些文件是可执行文件,我认为呢?还是他们指向可执行文件?这可能是问题的根源。
ls -l
lrwxrwxrwx 1 root other 57 Jul 15 2005 sparc-sun-solaris2.9-c++ -> /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++*
任何见识都会受到赞赏。
答案 0 :(得分:1)
尝试
max_depth
或
find -L . -type f -perm -u+rx | wc -l
或您需要的任何条件。
选项find -L . -name "sparc*" -type f -perm -u+rx | wc -l
指示-L
遵循符号链接,而不是处理链接本身。 (例如,参见https://www.unix.com/man-page/posix/1p/find/)
例如带有符号链接
find
sparc-sun-solaris2.9-c++ -> /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++*
的行为就像文件find
将直接位于/usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++
如果您的sparc-sun-solaris2.9-c++
不支持选项find
,则可以这样尝试-L
:
-follow