1

I wrote a script to find all folders that contain executable files. I was first seeking a oneliner command but could find one. (I especially tried to use sort -k -u).

. The script works fine but my initial question remains: Is there a oneliner command to do that?

#! /bin/bash
find $1 -type d | while read Path
do
X=$(ls -l "$Path" | grep '^-rwx' | wc -l)
if ((X>0))
then
    echo $Path
fi
done
quickbug
  • 4,708
  • 5
  • 17
  • 21
  • Possible duplicate: http://stackoverflow.com/questions/4458120/unix-find-search-for-executable-files There's your answer. –  Dec 08 '13 at 18:16
  • @HermanTorjussen: this question is about finding directories with executable files in them, a bit different from your proposed dup. – Mat Dec 08 '13 at 18:17

1 Answers1

3

Using find:

find $1 -type f -perm /111 -exec dirname {} \; | sort -u

This finds all files with permission 111 (i.e. rwx) but then we output only the directory name. To avoid duplicates, sort -u is used.

As pointed out by Paulo Almeida in the comments, this would also work:

find $1 -type f -perm /111 -printf "%h\n" | sort -u
Community
  • 1
  • 1
pfnuesel
  • 14,093
  • 14
  • 58
  • 71