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?
Asked
Active
Viewed 3.9k times
11
-
1This 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 Answers
21
You can do this with grep. grep -n 'search-term' *.c
will give you the filename and line number where the term appears.

arunkumar
- 32,803
- 4
- 32
- 47
-
-
3You can use `grep -nr ...` to search recursively inside sub-directories. – arunkumar Sep 29 '11 at 16:43
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
- 20,383
- 7
- 59
- 72