Do the following:

grep -rnw '/path/to/somewhere/' -e "pattern"
  • -r or -R is recursive,
  • -n is line number, and
  • -w stands match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.
  • Along with these, --exclude or --include parameter could be used for efficient searching. Something like below:
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

This will only search through the files which have .c or .h extensions. Similarly a sample use of --exclude:

grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

Above will exclude searching all the files ending with .o extension. Just like exclude file it's possible to exclude/include directories through --exclude-dir and --include-dir parameter; for example, the following shows how to integrate --exclude-dir:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

This works very well for me, to achieve almost the same purpose like yours.

For more options :

man grep

Simple But Useful Samples About 'grep' Command(简单实用的grep 命令)的更多相关文章

  1. 简单实用的Windows命令(二)

    昨天简单的记录了几个非常简单实用的Windows命令,不过我又想起来还有两个我在实际的工作中也是经常用到的命令——PING和IPCONFIG,不过我在工作中的使用都是非常简单的,用PING命令检测对应 ...

  2. 简单实用的Windows命令(一)

    前几天新买了一台笔记本电脑,使用了一下几个简单的查看电脑配置的命令,觉得非常的不错,在此记录一下 一:运行命令的方式有两种 1:使用快捷键WIN+R,然后在弹出的“运行”对话框中输入对应的命令 2:在 ...

  3. Github最简单实用的Git命令指南

    create a new repository on the command line   echo "# test" >> README.md git init gi ...

  4. 简单实用的git命令

    1.下载项目 先进入目录然后使用jit $ git clone +"url" 2.项目配置 $ composer install 3.上传项目 $ git add . () $ g ...

  5. Regular Expressions in Grep Command with 10 Examples --reference

    Regular expressions are used to search and manipulate the text, based on the patterns. Most of the L ...

  6. 15 Practical Grep Command Examples In Linux / UNIX

    You should get a grip on the Linux grep command. This is part of the on-going 15 Examples series, wh ...

  7. grep的简单理解

    概述: grep最早由肯·汤普逊写成.原先是ed下的一个应用程序,名称来自于g/re/p(globally search a regular expression and print,以正则进行全域查 ...

  8. Linux下好用的简单实用命令

    1.你是否为在输入了一大串命令之后发现第一个字符打错了而苦恼?只能删除重来嘛?或者一步步左移光标? NO,一个组合键轻松搞定 Ctrl+A -----到命令行首 Ctrl+E ------到命令行末 ...

  9. Linux的简单介绍和常用命令的介绍

    Linux的简单介绍和常用命令的介绍 本说明以Ubuntu系统为例 Ubuntu系统的安装自行百度,或者参考http://www.cnblogs.com/CoderJYF/p/6091068.html ...

随机推荐

  1. 使用EasyBCD 从硬盘安装 deepin2014.1

    EasyBCD config  code: title Install Deepin2014 root (hd0,1) kernel (hd0,1)/vmlinuz boot=casper iso-s ...

  2. 关于R语言的一些编程经验

    一个晚上写出一个能用的程序…… 来说说遇见的问题吧 zqw<-read.table(file = "c:/data/zqw.txt") zqw<-data.frame( ...

  3. ElasticSearch(2)-文档

    上一篇 ES(1) 官网原地址:https://www.elastic.co/guide/en/elasticsearch/reference/1.7/_cluster_health.html ES权 ...

  4. [转]整理jquery使用好习惯

    1.选择器Selector的使用 1)使用id定位性能最好   1.$("#id") 2)使用标签名定位,性能其次   1.$("p"),$("div ...

  5. LNK2019解决思路

    虽然官网给出了很多可能的原因,最可能的原因还是因为缺少某个库文件.最近解决的一个为例总结一下思路 Winmm.lib; ad_win32.obj : error LNK2019: unresolved ...

  6. insertMany

    结果:

  7. 。◕‿◕。TMD

    。◕‿◕。TMD TimeLimit: 2000/1000 MS (Java/Others)  MenoryLimit: 32768/32768 K (Java/Others) 64-bit inte ...

  8. 【ADT】队列的基本C语言实现

    queue.h #ifndef _QUEUE_H_ #define _QUEUE_H_ #include <stdbool.h> #define MAXQUEUE 10 // 定义队列类型 ...

  9. MFC下MCI的使用播放音乐

    最近研究了一下MFC下的音乐的播放,主要使用了MCI 1.需要包含的库文件 在链接资源里(link)添加库文件VFW32.lib winmm.lib 2.包含的头文件 #include <mms ...

  10. sql 判断表是否存在,判断列是否存在

    判断表是否存在: 语法: SELECT * FROM dbo.SysObjects where id = object_id(N'表名') 例子: SELECT * FROM dbo.SysObjec ...