11

I have a bunch of files organized into directories..All these are text files (c/c++). I am trying to understand this code and i need to look at the declarations of many variables..How can i use find command to get the exact location( File Name with line number(s) ) using Find command in ubuntu linux?? Or is there any graphical tool for doing the same?

nikhil
  • 8,677
  • 21
  • 54
  • 81
  • 1
    This feature should be provided by your IDE. See [C++ IDE for Linux?](http://stackoverflow.com/questions/24109/c-ide-for-linux) – jfs Sep 29 '11 at 16:29
  • Is there any graphical tool to do the same??? – nikhil Sep 29 '11 at 16:31
  • The second answer from [the question I've linked](http://stackoverflow.com/questions/24109/c-ide-for-linux) mentions: Code::Blocks, Eclipse CDT. [Search linux ide on stackoverflow](http://stackoverflow.com/search?q=%5Blinux%5D+ide). – jfs Sep 29 '11 at 16:41

2 Answers2

19

You can do this with grep. grep -n 'search-term' *.c will give you the filename and line number where the term appears.

arunkumar
  • 30,367
  • 4
  • 31
  • 47
8
find . -name *.c -exec grep -Hn "your search term here" {} \;

If you really want to use find.

EDIT

explanation

find . -name *.c - find files in current dir and below where name is like *.c

-exec - execute command that follows

grep -Hn - grep and print results with file name and line number of match

{} \; - {} marks where the name of each file found will be substituted and the backslash- semicolon marks the end of the command to execute.

ring bearer
  • 19,685
  • 7
  • 57
  • 70