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

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

    GREP: Global Regular Expression Print/Parser/Processor/Program.
    You can use this to search the current directory.
    You can specify -R for "recursive", which means the program searches in all subfolders, and their subfolders, and their subfolder's subfolders, etc.

    grep -R "your word" .
    

    -n will print the line number, where it matched in the file.
    -i will search case-insensitive (capital/non-capital letters).

    grep -inR "your regex pattern" .
    

提交回复
热议问题