开发者

Find Command that returns line number of the string

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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜