3
find . -iname '*.rar' -execdir ls {} +

this will not work under OSX Lion, yielding ls: blabla.rar: No such file or directory etc..

Additionally, above will work under Linux. However, it will invoke ls as many times as it find result. Tested with simple cat $# script.

So I see 2 problems with -execdir

  • under Linux it will NOT combine search result as stated in manual when using {} +
  • under OSX it will NOT change directory as stated in manual, again using {} +

Wanted to confirm that this is buggy and not my misunderstanding.

Pablo
  • 28,133
  • 34
  • 125
  • 215

2 Answers2

3

I don't know about Mountain Lion, but it's a known bug in GNU findutils, apparently fixed in the 4.5 branch (check your find --version). See https://savannah.gnu.org/bugs/?19593

There is also this bug: https://savannah.gnu.org/bugs/?29949 in find version 4.5.9, which matches the Mountain Lion symptom. Perhaps you should check both version numbers.

rici
  • 234,347
  • 28
  • 237
  • 341
  • Sounds like same symptoms, tried with pwd originally, not changing directory. Not even sure how to check findutil version on Lion... `--version` doesn't work. – Pablo Oct 25 '12 at 17:59
  • @Pablo if it doesn't respond to --version, it's not GNU find; it could well be FreeBSD find. I no longer have either a Mac or a FreeBSD box handy, so I can't help you there, but you could try Googling for FreeBSD bug reports. – rici Oct 25 '12 at 18:25
0

On Linux does it execute ls once for every file or once for every sub-directory? From man find (GNU findutils version 4.4.2):

As with the -exec action, the ‘+’ form of -execdir will build a command line to process more than one matched file, but any given invocation of command will only list files that exist in the same subdirectory.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • I've just tried on Linux to put files under same sub-directory. Still I see echo $# will give me one invocation per file, nothing is combined. – Pablo Oct 25 '12 at 17:43
  • `find . -iname "*.asd" -execdir test.sh {} +` is the test script. `test.sh` contains echo `$#`. – Pablo Oct 25 '12 at 17:45