自动忽略grep中的文件 [英] Automatically ignore files in grep

查看:134
本文介绍了自动忽略grep中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索某些东西(类似于svnignore或gitignore)时,是否可以使用grep忽略某些文件?在搜索源代码时,我通常会使用类似的东西.

Is there any way I could use grep to ignore some files when searching something, something equivalent to svnignore or gitignore? I usually use something like this when searching source code.

grep -r something * | grep -v ignore_file1 | grep -v ignore_file2

即使我可以为grep设置别名来忽略这些文件也很好.

Even if I could set up an alias to grep to ignore these files would be good.

推荐答案

--exclude选项也将起作用:

grep  perl * --exclude=try* --exclude=tk*

这会在当前目录中的文件(不包括以trytk开头的文件)中搜索perl.

This searches for perl in files in the current directory excluding files beginning with try or tk.

这篇关于自动忽略grep中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆