up vote 8 down vote favorite
1
share [g+] share [fb]

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

link|improve this question

36% accept rate
Linx? Or Linux? – Wim ten Brink Sep 10 '09 at 12:01
feedback

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

This question came from our site for professional and enthusiast programmers.

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).

link|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
8  
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 2 more comments
feedback

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.

link|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
2  
Then you should try the "-perm +" version which is now deprecated in GNU find: find . -perm +111" – innaM Sep 10 '09 at 19:32
feedback

Your Answer

 
or
required, but never shown

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