How to find files containing two strings together in Linux?
grep -l string2 `grep -l string1 /path/*`
which is the same as
grep -l string2 $(grep -l string1 /path/*)
Edit: heres why grep string1 /path/* | grep string2
doesn't do what I think alwbtc wants.
$ cd /tmp
$ cat a
apples
oranges
bananas
$ cat b
apples
mangoes
lemons
$ cat c
mangoes
limes
pears
$ cd ~
$ grep apples /tmp/* | grep mangoes
$
Nothing found, but file b contains both strings.
Here's what I think alwbtc wants
$ grep -l apples $(grep -l mangoes /tmp/*)
/tmp/b
Pipe one grep
into another:
grep "string1" /path/to/files/* | grep "string2"