Getting the files first
Lets say that you are looking only for files with ext *.c use:
$ find . -type f -name "*.c"
This finds all such files from (.) the current directory. If you need to find something from some other directory use:
$find /path_to_the_directory -type f -name "*.c"
The -type f looks only for files.
Now if you want to find both *.c and *.h files use:
$find . -type f -name "*.c" -or -name "*.h"
You can use -or (OR) -o to add more such extensions
$find . -type f -name "*.c" -or -name "*.cpp" -or -name "*.h"
This would list all the files with the extension *.c, *.cpp and *.h
If you want to use regular expressions you can use:
$find . -type f -name '\*\.[ch]'
This will list all the files with extension *.h or *.c
Similarly if you want files which start with a Capital letter you can use
$find . -type f -name '[A-Z][a-x]*\.[ch]'
and so on.or if you want a complex regular expression:
$find . -type f -name '[A-Z0-9._%+-]+\.[ch]'
Searching the string in the files got
Now that we can got our list of files which we are interested in, let us try to search for our string. Assuming that I am trying to find (say) "MyFunction" I would use
$ grep "MyFunction" `find . -type f -name '[A-Z]\*\.[ch]'`
This would search in each and every file as found by find and would try to grep for MyFunction.
If you don't know the case, you can ignore it using -i with grep
grep -i "MyFunction" `find . -type f -name '[A-Z]\*\.[ch]'`
Update: Using egrep with Xargs to handle long argument list -> here