Friday, August 23, 2013

Linux - Recursively Finding Files Containing Text

Find all files at current directory and below containing the string "stringToSearchFor", and include the line number (that's what the "-n" option does):

grep -r  -n stringToSearchFor .

If you want to include 1 lines before, and 2 lines after the occurrence in the file as well, use


grep -r  -n -B 1 -A 2 stringToSearchFor .


No comments:

Post a Comment