# Just how to find all binary executables recursively within a directory site?

If I make use of find command similar to this:

find /mydir/mysubdir -executable -type f


all executable files are detailed (leaving out directory sites), and also consisting of executable manuscript documents (like script.sh, etc). What I intend to do is checklist just binary executable files.

0
2019-05-04 03:45:33
Source Share

Here's a means to exclude manuscripts, i.e., files whose first 2 personalities are #! :

find -type f -executable -exec sh -c 'test "$(head -c 2 "$1")" != "#!"' sh {} \; -print


For some sort of files, it's unclear whether you desire them identified as manuscripts or binary, as an example bytecode files. Relying on just how points are set up, these might or might not start with #!. If these issue to you, you'll need to make the internal shell manuscript extra intricate. As an example, below's just how you could include ELF binaries and also Mono executables and also Objective Caml bytecode programs yet not various other sort of executables like shell manuscripts or perl manuscripts or JVM bytecode programs :

find -type f -executable -exec sh -c '
case "$(head -n 1 "$1")" in
?ELF*) exit 0;;
MZ*) exit 0;;
#!*/ocamlrun*) exit 0;;
esac
exit 1
' sh {} \; -print

0
2019-05-07 23:02:54
Source

You could attempt the file energy. According to the manpage :

The magic examinations are made use of to look for files with information specifically dealt with layouts. The approved instance of this is a binary executable (assembled program ) a.out documents, whose layout is specified in, and also perhaps in the typical include directory site.

You could need to experiment with the normal expression yet something like :

\$ find -type f -executable -exec file -i '{}' \; | grep 'x-executable; charset=binary'

.

documents has great deals of alternatives, so you could intend to take a more detailed consider the male web page. I made use of the first alternative I located that appeared to result easily-to-grep result.

0
2019-05-07 22:03:25
Source