Find string in files of a type

From snippet wiki
Jump to navigation Jump to search

If you need to find a string within a tree of files, searching only for some extensions:

find . -type f -name '*.c' -print0 | xargs -0 grep "Error in calling open"

This will search for the given string Error in calling open within all C code files.

The options -print0 and -0 are there to handle file paths with spaces. (Don't ask, only windows people could have such an idea)