How to execute files which are found by find

2

I have some executable files under a directory tree. I want to find them and execute them the most simple way. I've tried this so far: find . -perm 0775 -type f | xargs exec But exec is not an executable, it is a bash internal. I could create a wrapper script which could look like this:

#!/bin/bash
# exec.sh
exec $1

And then could run find . -perm 0775 -type f -exec ./exec.sh {} \; But there's gotta be a more elegant and shorter way of doing that.

Gabor Marton

Posted 2014-07-23T09:50:43.517

Reputation: 347

Answers

5

Just drop the script.

find . -perm 0775 -type f -exec '{}' ';'

works just fine!

Jan Hudec

Posted 2014-07-23T09:50:43.517

Reputation: 885

0

xargs is not really suited to doing this; it is mainly meant to supply a fixed command with arguments read from standard input.

But you can call the programs directly using a simple shell loop:

find . -perm 0775 -type f | while read program; do
                                $program
                            done

JyrgenN

Posted 2014-07-23T09:50:43.517

Reputation: 121