"grep -rnw": search for a string in all files
Asked Answered
E

1

44

Related question: How do I find all files containing specific text on Linux?

I have been using the command mentioned in the answer of above question to search for string occurences in all files:

grep -rnw '/path/to/somewhere/' -e "pattern"

However lately I encountered a problem, shown in the following picture: enter image description here

Looks like this command only recognizes strings that stand out as a word or something. How should I modify the command to improve my search result?

Ensile answered 9/8, 2016 at 19:31 Comment(0)
U
67

explainshell helpfully explains your command, and gives an excerpt from man grep:

   -w, --word-regexp
          Select  only  those  lines  containing matches that form whole words. 

So just remove -w since that explicitly does what you don't want:

grep -rn '/path/to/somewhere/' -e "pattern"
Unsuccess answered 9/8, 2016 at 20:2 Comment(2)
Be advised, "pattern" is a regexp.Lowelllowenstein
Thank you. Additionally, -r, --recursive, -n, --line-numberAcidophil

© 2022 - 2024 — McMap. All rights reserved.