0

They should both get the files that are executable but I get different numbers

[user@j6727961 ~]$ sudo find /usr -perm /a=x | nl
    1   /usr
     2  /usr/bin
     3  /usr/bin/nroff
     4  /usr/bin/gzexe
     5  /usr/bin/catchsegv
     6  /usr/bin/diff
     7  /usr/bin/gzip
     8  /usr/bin/gencat
     9  /usr/bin/diff3
    10  /usr/bin/zcat
    11  /usr/bin/getent
    12  /usr/bin/sdiff
    13  /usr/bin/zcmp
    14  /usr/bin/iconv
    15  /usr/bin/db_recover
    16  /usr/bin/ldd
    17  /usr/bin/unxz
    18  /usr/bin/zdiff
    19  /usr/bin/locale
    20  /usr/bin/xz
    21  /usr/bin/zgrep
    22  /usr/bin/localedef
    23  /usr/bin/xzcat
-
-
-
-
 17112  /usr/local/share/man/man8x
 17113  /usr/local/share/man/man9
 17114  /usr/local/share/man/man9x
 17115  /usr/local/share/man/mann
 17116  /usr/local/src
 17117  /usr/src
 17118  /usr/src/debug
 17119  /usr/src/kernels
 17120  /usr/tmp

and with the -executable flag:

[user@j6727961 ~]$ sudo find /usr -executable | nl
[sudo] password for user: 
     1  /usr
     2  /usr/bin
     3  /usr/bin/nroff
     4  /usr/bin/gzexe
     5  /usr/bin/catchsegv
     6  /usr/bin/diff
     7  /usr/bin/gzip
     8  /usr/bin/gencat
     9  /usr/bin/diff3
    10  /usr/bin/zcat
    11  /usr/bin/getent
    12  /usr/bin/sdiff
    13  /usr/bin/zcmp
    14  /usr/bin/iconv
    15  /usr/bin/db_recover
    16  /usr/bin/ldd
    17  /usr/bin/unxz
    18  /usr/bin/zdiff
-
-
-
-
 12218  /usr/local/share/man/man4x
 12219  /usr/local/share/man/man5
 12220  /usr/local/share/man/man5x
 12221  /usr/local/share/man/man6
 12222  /usr/local/share/man/man6x
 12223  /usr/local/share/man/man7
 12224  /usr/local/share/man/man7x
 12225  /usr/local/share/man/man8
 12226  /usr/local/share/man/man8x
 12227  /usr/local/share/man/man9
 12228  /usr/local/share/man/man9x
 12229  /usr/local/share/man/mann
 12230  /usr/local/src
 12231  /usr/src
 12232  /usr/src/debug
 12233  /usr/src/kernels
 12234  /usr/tmp
1

According to man find:

   -perm /mode
          Any  of the permission bits mode are set for the file.

So -perm /a+x will match a file with any executable bit set.

   -executable
          Matches  files  which  are  executable and directories which are
          searchable (in a file name resolution sense).  This  takes  into
          account  access  control  lists  and other permissions artefacts
          which the -perm test  ignores.   This  test  makes  use  of  the
          access(2) system call, and so can be fooled by NFS servers which
          do UID mapping (or root-squashing), since many systems implement
          access(2)  in  the client's kernel and so cannot make use of the
          UID mapping information held on the server.  Because  this  test
          is  based only on the result of the access(2) system call, there
          is no guarantee that a file for which  this  test  succeeds  can
          actually be executed.

So -executable will match a file that the current user can access according to the access() system call.

1

-executable finds files or directories which are executable or traversable in the sense that the system call access says that they are executable or traversable by the user running find -- in your case, root. -perm looks at the file mode bits. In most cases, the most striking difference between them comes from the fact that by default find does not dereference symbolic links; this means that -perm will by default look at the file mode bits of the link (usually 0777), whereas -exec will look at the file mode bits of the referenced file, because access always dereferences symbolic links.

Summary: usually the difference is that find -perm /a=x will include all symbolic links, whereas find -executable will include only those symbolic links which point to executable files or traversable directories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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