find string in all files linux code example

Example 1: find text in folder

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

Example 2: bash find all files containing string

grep -r '/path/to/somewhere/' -e 'pattern'

Example 3: shell find string in directory

grep -R "string_to_search" *

Example 4: linux find file containing text

# syntax 
# find *</path/to/dir> -name '*<file(s)-to-search>' -exec grep '*<string-to-find>' {} /dev/null \;

# example
find 'C:/Users/JacquesK' -name '*.*' -exec grep 'Random text to find' {} /dev/null \;

Example 5: find text in linux file

grep 'word' filename
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName