Search for specific string in files/directories with line number in linux


You want to search in a directory or some files for a specific string and you also want to know the number in the file that the text is found.


Use grep with the -n for the line number and the -r for directory search as in the following:

grep -n -r 'search_item' /path/to/folder/