I'm trying to use Unix's find command to count the number of executable files in a directory of a certain type, namely Solaris(MSB) executable's. I know I can get the count of all executable files in this directory fairly easy with

find . -type f -perm -u+rx | wc -l

however this doesn't count Solaris(MSB) executable files exclusively. I thought to remedy this I would just throw in a -name flag, something like this.

find . -name "sparc*" -type f -perm -u+rx | wc -l

This will correctly return that there are 6 only if I remove the part of the command that specify's that they need to be executable, if I keep this part of the command it returns a count of 0 which is "wrong". When I look at the ls -l command below I can see that these files are executable I think? or that they are pointing to an executable? This might be the root of the problem.

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++*

Any insight is appreciated.

1 Answers

1
Bodo On Best Solutions

Try

find -L . -type f -perm -u+rx | wc -l

or

find -L . -name "sparc*" -type f -perm -u+rx | wc -l

or whatever conditions you need.

Option -L instructs find to follow symbolic links instead of processing the link itself. (see e.g. https://www.unix.com/man-page/posix/1p/find/)

For example with the symbolic link

sparc-sun-solaris2.9-c++ -> /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++*

find should behave as if the file /usr/local/gnu/pkg/gcc-3.3.6/bin/sparc-sun-solaris2.9-c++ would be directly located at sparc-sun-solaris2.9-c++

If your find doesn't support option -L you can try -follow like this:

find . -follow -name "sparc*" -type f -perm -u+rx | wc -l