Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

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
share|improve this answer
2  
You can use -L instead of -or -type l to cause any stat calls made by find to return the stats of the file linked to, not the link itself. –  Ian C. Jan 8 at 7:27
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Symbolic syntax must be new -- thanks for pointing that out. I updated my answer so it uses octals and is backwards compatible with older OS X versions. –  Ian C. Jan 8 at 7:26
    
Oddly enough, that section of the 10.6 manpage is exactly the same as what you quoted.... which was enough to make me dig a little deeper and see what the heck was going on. Amended my response above. –  Kent Jan 8 at 7:49
1  
Conclusion: BDS command syntax is weird. –  Ian C. Jan 8 at 7:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.