I use a command to recursively find files containing a certain string1
:
find . -type f -exec grep -H string1 {} \\;
I need to
You can chain your actions and use the exit status of the first one to only execute the second one if the first one was successful. (Omitting the operator between primaries defaults to -and
/-a
.)
find . -type f -exec grep -q 'string1' {} \; -exec grep -H 'string2' {} \;
The first grep command uses -q
, "quiet", which returns a successful exit status if the string was found.