Find Command that returns line number of the string

前端 未结 2 1639
春和景丽
春和景丽 2021-01-04 18:40

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 vari

相关标签:
2条回答
  • 2021-01-04 19:33
    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 讨论(0)
  • 2021-01-04 19:36

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

    0 讨论(0)
提交回复
热议问题