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

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

    The following sample looks recursively for your search string in the *.xml and *.js files located somewhere inside the folders path1, path2 and path3.

    grep -r --include=*.xml --include=*.js "your search string" path1 path2 path3
    

    So you can search in a subset of the files for many directories, just providing the paths at the end.

提交回复
热议问题