0

How may I use grep (or any other tool) to search one string per file only once and also print that file name?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936

1 Answers1

2
grep -rFl "string" /path/
  • -r: search recursively (not standard but pretty common)
  • -F: fixed string search (as opposed to regexp pattern matching)
  • -l: List name of the file containing "string"

You can also use:

find /path -type f -exec  grep -lF "string" {} +

If your grep doesn't support -r.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Sourav
  • 1,253
  • 2
  • 11
  • 16