A handy tip for searching through source code using grep/find.

Thought this will be useful for navigating source code in any system. (from kernelnewbies.org)

“As you read through the code, you’ll need many times to lookup
the declaration or definition of this or that particular data
structure, macro or function. the most basic way to do so is to use a
combination of the grep (or egrep) and find` commands;

find . -exec grep --with-filename myfunction '{}' \;

Another way is,

find . -name '*.[chS]' | xargs egrep -n "myregularexpression";

If you have GNU grep (as virtually all Linux distributions do) then you can take advantage of its “recursive” flag:

egrep -r --include "*.[chS]" "myregularexpression" .

Add “-w” to avoid catching words in which your search term is a substring.

This
searches the current directory [and all subdirectories] for files
ending with .c, .h or .S, and runs egrep on each of them for the
pattern myregularexpression. Substitute myregularexpression with more
complex regular expressions.”

Powered by ScribeFire.

Last Updated on October 10, 2007 by SK

Leave a Reply

Your email address will not be published. Required fields are marked *