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

前端 未结 14 1789
一个人的身影
一个人的身影 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 04:00

    grep -nr 'yourString*' .
    

    The dot at the end searches the current directory. Meaning for each parameter:

    -n            Show relative line number in the file
    'yourString*' String for search, followed by a wildcard character
    -r            Recursively search subdirectories listed
    .             Directory for search (current directory)
    

    grep -nr 'MobileAppSer*' . (Would find MobileAppServlet.java or MobileAppServlet.class or MobileAppServlet.txt; 'MobileAppASer*.*' is another way to do the same thing.)

    To check more parameters use man grep command.

提交回复
热议问题