Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop find from searching after first result found?

Tags:

find

I am using 'find' to get the path to a dir called "out" and want it to stop looking after it is found. There can be some 350G worth of files in that dir so I REALLY want it to stop looking once it is found.

This works bu doesn't stop looking, takes too long..

find . -type d -name out  

This "ungreedy" approach also works but doesn't seem to stop either...

find . -type d -regex ".+/out/?"

I'm running this in perl, so I suppose I could write a recursive function that reads down a dir tree and does what I want. But is there a brake in "find" that I can apply once the first instance is found?

Thanks in Advance !

like image 770
daveg Avatar asked Dec 07 '25 13:12

daveg


1 Answers

Use -quit:

find . -type d -name out -print -quit

Manual for "find" tool is here.

like image 130
Marcin Orlowski Avatar answered Dec 12 '25 04:12

Marcin Orlowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!