Grep only the first match and stop

后端 未结 5 1961
误落风尘
误落风尘 2020-11-29 15:14

I\'m searching a directory recursively using grep with the following arguments hoping to only return the first match. Unfortunately, it returns more than one -- in-fact two

5条回答
  •  萌比男神i
    2020-11-29 15:41

    A single liner, using find:

    find -type f -exec grep -lm1 "PATTERN" {} \; -a -quit
    

提交回复
热议问题