Find all executable files within a folder in terminal

I have a folder myfolder that contains a huge hierarchy of files/folders.
How to find all executable files within this folder?

On Ubuntu this works: find . -executable -type f

But Mac OS X Mavericks (which also uses bash) fails to get it:

find: -executable: unknown primary or operator

This will find all files (not symlinks) with the executable bit set:

find . -perm +111 -type f

This will also find symlinks (which are often equally important)

find . -perm +111 -type f -or -type l

Here's how the command works if its not obvious:

  • find is obviously the find program (:
  • . refers to the directory to start finding in (. = current directory)
  • -perm +111 = with any of the executable bits set (+ means "any of these bits", 111 is the octal for the executable bit on owner, group and anybody)
  • -type f means the type is a file
  • -or boolean OR
  • -type l means the type is a symbolic link

I couldn't make Ian's answer work (10.6.8), but, the following gave the expected results:

find . -type f -perm +0111 -print

edit update

This seems to work as well!

find . -type f -perm +ugo+x -print

I guess the "x" is meaningless without the user/group/other specifiers.


From the man page for find in OS X:

 -perm [-|+]mode
         The mode may be either symbolic (see chmod(1)) or an octal number.  If the mode is symbolic, a
         starting value of zero is assumed and the mode sets or clears permissions without regard to the
         process' file mode creation mask.  If the mode is octal, only bits 07777 (S_ISUID | S_ISGID |
         S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO) of the file's mode bits participate in the comparison.
         If the mode is preceded by a dash (``-''), this primary evaluates to true if at least all of
         the bits in the mode are set in the file's mode bits.  If the mode is preceded by a plus
         (``+''), this primary evaluates to true if any of the bits in the mode are set in the file's
         mode bits.  Otherwise, this primary evaluates to true if the bits in the mode exactly match the
         file's mode bits.  Note, the first character of a symbolic mode may not be a dash (``-'').

So you need:

find . -type f -perm +0111 -print

Remember that OS X is BSD-based, not Linux based, so the Gnu commands you're used to in Linux distributions (of which find is one of them) aren't necessarily the same as they are in OS X. This isn't a shell difference, it's an operating system/operating system utility tools difference.


A very old question, I'm aware, but searching for a solution I may have found a better answer.

The main problem with using "find" is that it relies on an attribute set to executable, even if this attribute is set for a non-executable file.

MacOS comes with a handy little command-line tool "file", which displays file information, for example:

$> file *

Distribution:             directory
SomeFile.icns:            Mac OS X icon, 3272878 bytes, "ic09" type
MyPicture.png:            PNG image data, 1024 x 1024, 8-bit/color RGBA, non-interlaced
NSHelpers.pas:            Algol 68 source text, ASCII text
myProgram:                Mach-O 64-bit executable x86_64

As you can see, 'MyProgram' is an executable, and nicely indicated as such. Since old 32bit executables will have the phrase "executable" in this as well, the following should list all true executable (binaries):

file * | grep "executable"

Hope this will be useful to somebody looking for an answer to the same question as well.

Note: file does not seem to have a function to recurse through subdirectories.