Find a command that returns the line number of a line

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 the find command to get the exact location (file name with line numbers) using the find command in ubuntu linux? Or is there any graphic tool to do the same?

+7
source share
2 answers

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

+10
source
 find . -name *.c -exec grep -Hn "your search term here" {} \; 

If you really want to use find .

EDIT

explanation

find . -name *.c find . -name *.c - find files in the current directory and below, where there is a name * .c

-exec - execute the command that follows

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

{} \; - {} notes that the name of each found file will be replaced, and the backslash - semicolon marks the end of the command being executed.

+6
source

All Articles