How can I use grep to find a word inside a folder?

前端 未结 14 1800
一个人的身影
一个人的身影 2020-12-02 03:07

In Windows, I would have done a search for finding a word inside a folder. Similarly, I want to know if a specific word occurs inside a directory containing many sub-directo

14条回答
  •  孤街浪徒
    2020-12-02 03:43

    grep -nr search_string search_dir
    

    will do a RECURSIVE (meaning the directory and all it's sub-directories) search for the search_string. (as correctly answered by usta).

    The reason you were not getting any anwers with your friend's suggestion of:

    grep -nr string
    

    is because no directory was specified. If you are in the directory that you want to do the search in, you have to do the following:

    grep -nr string .
    

    It is important to include the '.' character, as this tells grep to search THIS directory.

提交回复
热议问题