Search code examples
linuxshellack

Find files where 2 given words occur in


(How) Can I find files where there are occurrences of 2 words in that same file, say Peter and James? Is it possible with ack-grep?


Solution

  • You can just grep twice:

    grep -l Peter * | xargs grep -l James
    

    The same works with ack:

    ack -l Peter * | xargs ack -l James
    

    You can replace the * with whatever other file list you might care about, or use find to generate a list for you.