![linux grep 递归](https://img-blog.csdnimg.cn/img_convert/aa23cf1982758ecedb3101c6635f22b3.png)
linux grep 递归
grep
is very useful command to search files and directories. What makes grep
powerful is that it can search file contents. We can search file content according to extension. Recursive behavior makes it more powerful by looking sub directories and files.
grep
是搜索文件和目录的非常有用的命令。 使grep
功能强大的原因是它可以搜索文件内容。 我们可以根据扩展名搜索文件内容。 通过查看子目录和文件,递归行为使其更强大。
Introduction to Linux Grep Command With Examples
递归-r选项(Recursive -r Option)
We will start with a simple example and only specifying recursive option -r
which is shortcut for “recursive”. In this example we will search files those have string import
. We will search /home
directory.
我们将从一个简单的示例开始,仅指定递归选项-r
,这是“递归”的快捷方式。 在此示例中,我们将搜索具有字符串import
文件。 我们将搜索/home
目录。
$ grep -r "import" /home/
![Recursive -r Option](https://img-blog.csdnimg.cn/img_convert/970f54ef0de0120bfbf491189460c45d.png)
指定文件名模式或扩展名(Specify File Name Pattern or Extension)
We can specify file pattern to search recursively. For example if we want to search the Python script or code files content we can use *.py
file pattern to look only those files recursively. In this example we will search for import
term. We will use --include
option.