2

The following command works on Ubuntu (GNU findutils 4.4.2) but not on Fedora (4.2.27)

time find . -maxdepth 1 -type f -executable -print

How do I find executable files using older version of find?

4 Answers 4

6
find . -maxdepth 1 -type f -perm /a+x

From the man:

-perm /mode

Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify ’u’, ’g’ or ’o’ if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test currently matches no files. However, it will soon be changed to match any file (the idea is to be more consistent with the behaviour of perm -000).

The EXAMPLES section has something where the find shows all writable files. A find on executable files will be similar to the given example.

3
find . -type f -perm -111

Note: -111 not 111

1
find . | file -f - | grep executable

might be much slower, but also will look for things that are executables, but not necessarily permissioned as such. You may need to change what you grep for to improve accuracy (this would also match a file called "executable.jpg") narrow results (you may only be looking for a certain type of exe) and you might want to prettify the output later.

Really would be useful to know why you are doing this in order to construct the best answer :)

2
  • This will find files that might be executable, but not files that are executable. Apr 19, 2012 at 12:10
  • indeed it will - as I said, all files that are executables (you put it more cleanly!). We don't know what the OP is up to, so I thought let's have a bit of variety in answers ;)
    – Tom Newton
    Apr 20, 2012 at 8:29
0
time find . -maxdepth 1 -type f -perm /a=x -print

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .