find, xargs, gep -- multiple words in files

Andrew C Aitchison ubuntu at aitchison.me.uk
Tue Feb 3 19:46:55 UTC 2026


On Tue, 3 Feb 2026, bruce wrote:

> hi.
>
> Forgive me -- this is a basic question, but I  can't find the solution(s)
> that I had (older drive  crashed last  year).
>
> I haven't been able to cobble together a working solution based on net
> searches either -- so it must be user error..
>
> I'm trying to use 'find', 'grep', 'xargs' to find multiple "words" in a
> given line/file
>
> find /foo/projects -name "*.*" | xargs grep -i "review"
>
> will find the files with "review".. no prob...
>
> but...
>
> trying different cmds using the above as a base, haven't really worked.
> --And, I'm not apparently finding the example with the (find, xargs, grep)
> for finding files with multiple words.
>
> Any thoughts/comments?

Not quite sure what you want but
I am assuming that the multiple words may be on different lines.

If you want all the files containing "review" and "experiment",  try

  find /foo/projects -name "*.*" | xargs grep -il "review" | xargs grep -i "experiment"

The '-l' on the first grep will make it print just the filenames, then you 
do it again for "experiment", but this time you (possibly) want the 
maching lines.

If any of the filenames include spaces they will mess things up.
Either fix this with
    find ... -print0 | xargs -r0 grep -ilZ "review" | xargs -r0 grep -i "experiment"
or chose one of the newer alternatives to find/xargs - GNU 'parallel' comes to mind;
some of these handle spaces in filenames automatically.

-- 
Andrew C. Aitchison                      Kendal, UK
                    andrew at aitchison.me.uk



More information about the ubuntu-users mailing list