Linux – Searching a number of files for a string in LInux

linuxsearch

How do I search files, some of which might be directories (in this case recursively) for a given string?

I'd like to search source files for a class definition, so it would also be great if there was the name of the containing file before each output string.

Best Answer

You could use grep:

grep -rn 'classname' /path/to/source

This will also print the line number next to each match.

Case insensitive:

grep -rin 'classname' /path/to/source

Search non-recursively in all cpp files:

grep -n 'classname' /path/to/source/*.cpp
Related Topic