Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to find the executable files under a certain directory in linux?

share|improve this question
Linx? Or Linux? – Wim ten Brink Sep 10 '09 at 12:01
@WimtenBrink GNU/Linux ! :p – Shadok Feb 23 '12 at 14:31

migrated from stackoverflow.com Sep 10 '09 at 12:46

2 Answers

use the -executable option:

find <dir> -executable

if you want to find only executable files and not searchable directories, combine with -type f:

find <dir> -executable -type f

EDIT:

checking with the comments i see there’s no type x. i’m sorry, this was my mistake. checking for executable files can be done with -perm (not recommended) or -executable (recommended, as it takes ACL into account).

share|improve this answer
This will return files with the execute turned on only. A more thorough analysis would check for a shebang line or whether the file is binary – ennuikiller Sep 10 '09 at 12:04
12  
a shebang doesn’t mean they’re executable. it tells us only which interpreter to use. and by linux definition “executable files” are files with the executable (x) bit set – knittl Sep 10 '09 at 12:09
1  
What version of find supports that type for -type? man find lists b, c, d, p, f, l, s and D on my system. – innaM Sep 10 '09 at 15:51
Same here, my find doesn't have a -type x either. – davr Sep 10 '09 at 17:17
For some reason I always think that "-type x" will work too. I can only imagine it was available on some flavour of Unix I used once. – Dave Webb Sep 21 '09 at 10:39
show 4 more comments

Use the find's -perm option. This will find files in the current directory that are either executable by their owner, by group members or by others:

find . -perm /u=x,g=x,o=x

Edit:

I just found another option that is present at least in GNU find 4.4.0:

find . -executable

This should work even better because ACLs are also considered.

share|improve this answer
This only works on a newer version of find. The one that comes by default with CentOS gives the error find: invalid mode /u=x,g=x,o=x'` – davr Sep 10 '09 at 17:18
5  
Then you should try the "-perm +" version which is now deprecated in GNU find: find . -perm +111" – innaM Sep 10 '09 at 19:32

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.