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:
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?
To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.
Select Search > Find in Files from the menu. If you like keyboard shortcuts better, use Ctrl-Shift-F to open the search window instead. The find in files configuration window is pretty easy to use as you can ignore most options if you don't require them.
Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. Using the grep command, we can recursively search all files for a string on a Linux.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With