Searching for files via do shell script

I need a way to search for a specific file on a mounted network volume. I have been trying to use do shell script to make use of the ‘find’ command in terminal, but I also need it to stop looking once it has found a match. There doesn’t seem to be any way to get ‘find’ to only return the first match. Does anybody know of a better way to go about this? I’d prefer a fairly fast solution. There aren’t a huge amount of files to search for, but the filesystem I’m looking in is pretty bushy. I’ve tried a couple of OSAX, none of which worked. I’m on OSX 10.3.8, AS 1.9.3.

Thanks,

B!ll

Here’s a hack I came up with that seems to work. I’ve only tested it from the zsh prompt, so you’ll probably have to adjust special character escapes to get it to work from script editor:

rm /tmp/MyTestFile; find . -exec test -e /tmp/MyTestFile ; -prune -o -name MyFileName -print -exec touch /tmp/MyTestFile ;

Basically what I’m saying is:

→ Make sure no file exists at /tmp/MyTestFile.
→ Perform a find with the following logic:

  1. If the file /tmp/MyTestFile exists, stop the find (*).
  2. If the file named “MyFileName” is found, print its name and then create the file /tmp/MyTestFile.

(*) It doesn’t really stop the find, it just prevents it from descending into any new directories. This has the effect of stopping very soon, in most cases.

Daniel