linux grep 递归_如何在Linux中通过子目录递归使用Grep命令?

linux grep 递归

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

Linux Grep命令简介和示例

递归-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
Recursive -r Option
递归-r选项

指定文件名模式或扩展名(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 --includeoption.

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值