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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Sep 10 '09 at 12:46

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

Here is a kind of BASH script, it is not-bad is what I can say :) – AjayKumarBasuthkar Mar 26 '14 at 7:49
What about using the standard file command? – Breakthrough Dec 8 '14 at 14:22
For anyone wanting to do this on a Mac (tested on OS X 10.9.5): ls -l | egrep '^[^d]..x..x..x.*$' The above will list all executables (for all/user and group) in the current directory. Note: The -executable option does not work on a Mac hence the above workaround. – techfoobar Dec 8 '14 at 14:28
Also relevant: Unix find: search for executable files – Slothworks Aug 14 '15 at 6:10

Checking for executable files can be done with -perm (not recommended) or -executable (recommended, as it takes ACL into account). To 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
share|improve this answer
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
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
If you have an old version of find (probably before 4.3.8) which lacks -executable use find . -perm /u=x,g=x,o=x. – Ludwig Weinzierl May 14 '10 at 19:06
find: invalid predicate -executable' on RHEL – SSH This May 17 '13 at 20:57

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


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

A file marked executable need not be a executable or loadable file or object.

Here is what I use:

find ./ -type f -name "*" -not -name "*.o" -exec sh -c '
    case "$(head -n 1 "$1")" in
      ?ELF*) exit 0;;
      MZ*) exit 0;;
exit 1
' sh {} \; -print
share|improve this answer
What does this do? – DerMike Jan 14 '15 at 8:04
@DerMike, It is one of the ways to find executable in current directory, including .so files, even if a file is not marked executable it can discover. – AjayKumarBasuthkar Jan 14 '15 at 21:59
Well, I mean, how does it do that? – DerMike Jan 15 '15 at 10:05
It reads from the header of the file to discover, every binary file or script file has header. – AjayKumarBasuthkar Jan 15 '15 at 13:44

Your Answer


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.