[Shell]在一个目录及其子目录内的指定类型的文件中搜索某个字符串

来源:互联网 发布:网络品牌续费上海勤拙 编辑:程序博客网 时间:2024/05/16 10:27

要求:

在Dir目录及其子目录下的所有的"*.py"文件中搜索字符串“xxx”


1. 首先使用find命令找出所有的"*.c"文件,然后使用grep命令查找:

find Dir -name "*.py" | xargs grep xxx




2. 使用grep命令的--include选项

       --include=GLOB
              Search  only  files whose base name matches GLOB (using wildcard
              matching as described under --exclude).

grep -r --include="*.py" "xxx" Dir

0 0
原创粉丝点击