Crazy Idea


how to (politely) stop a find process after the 1st match
April 26, 2007, 12:26 am
Filed under: howto

LazyWeb,

I’m on windows(cygwin); Every now and then, I run a “find” task which finds the file and then continues searching for a lot more time . I’d like it to abort after the 1st match.

eg : find . -type f - iname “foo.txt” -exec xemacs.bat {} ;

Is there a way to tell find that “hey, after you find the 1st match(a file), do the exec piece and then quit the find part of it ?

I know that I could create a .bat file that finds who its parent process is and terminates it. But is there a more nicer way ? :-)

Thanks for any hints.


2 Comments so far
Leave a comment

Don’t use -exec

find . -type f -iname “foo.txt”|head -1 |xemacs.bat -

This, of course, presumes that the first foo.txt is always the right one.

Comment by Gautam Guliani June 14, 2007 @ 9:27 pm

Hi Gautam,

Thanks for the tip. That works!! Now I have one more convenience batch file

BR,
~A

Comment by anjanb June 16, 2007 @ 12:37 am



Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>