打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
grep 搜索目录时,怎样排除某些目录?

使用 grep 搜索目录时,会将一些隐藏目录也给搜进去,比如 .git 目录。如何在使用 grep 时排除这些目录呢?


    使用 --exclude-dir 选项。

语法

--exclude-dir=DIR
Exclude directories matching the pattern DIR from recursive searches.

单个目录示例

grep -E "http"  ./ -R --exclude-dir=.git 

多个目录示例

grep -E "http"  . -R --exclude-dir={.git,res,bin}

多个文件示例

附赠一个,排除扩展名为 java 和 js 的文件

grep -E "http"  . -R --exclude=*.{java,js}
0
秦书磊 129 2014年12月08日 回答

grep太罗嗦,用ack吧。源码搜索的不二之选~默认排除各种版本库,可以指定多种源文件类型。

─(~/.cheat)(ruby-1.9.3-p547@rails3.1.1)────────────────────────────────────────────────────────────────────(shuleiqin@shuleiqin-F8Vr:pts/0)─┐└─(23:14:07 on master)──> ls                                                                                                  ──(一,12月08)─┘alias  bash  crontab  DirectoryArchitecture  echo    Git   kill  MachineProperties  passwd  Python     Regex     tree     usermod  Viawk    Bash  df       du                     export  grep  less  markdown           python  README.md  shutdown  useradd  vi       zip┌─(~/.cheat)(ruby-1.9.3-p547@rails3.1.1)────────────────────────────────────────────────────────────────────(shuleiqin@shuleiqin-F8Vr:pts/0)─┐└─(23:14:16 on master)──> ack grep                                                                                             ──(一,12月08)─┘grep2:grep pattern file5:grep -i pattern file7:# Recursively grep for string <pattern> in folder:8:grep -R pattern folder11:grep -Rl {search} {path}14:grep -Rli {search} {path}17:grep -f pattern_file file20:grep -v pattern file22:# You can grep with regular expressions23:grep "^00" file  #Match lines starting with 0024:grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" file  #Find IP add28:grep -rnw 'directory' -e "pattern"30:# Exclude grep from your grepped output of ps.32:ps aux | grep '[h]ttpd'35:ps aux | grep -E --color 'bash
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
find和grep的高级用法
git , vim , ls 全局配置
grep 搜索时忽略.svn目录
grep命令最经常使用的功能总结
CFD工具OpenFOAM培训三——OF概述、架构及环境
73条日常Linux shell命令汇总,总有一条你需要!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服