How may I use grep (or any other tool) to search one string per file only once and also print that file name?
Asked
Active
Viewed 75 times
0
Kusalananda
- 320,670
- 36
- 633
- 936
Jignesh Patel
- 31
- 3
1 Answers
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
-
1@Kusalananda, sorry, I just edited the recommendations at [that Q&A](/q/321697) in. Sourav, I'd suggest you read it. – Stéphane Chazelas Jun 28 '17 at 20:29