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. POCO系列之——延迟加载

    当我们进行查询的时候,哪些关系的数据将会被加载到内存呢?所有相关的对象都需要吗?在一些场合可能有意义,例如,当查询的实体仅仅拥有一个相关的子实体,但是,多数情况下,你可能只需要加载部分数据,或者你喜欢 ...

  2. cmd alias 自定义命令

    简短步骤:1.关闭所有在运行的CMD窗口2.创建文件C:\cmd-alias.bat,包含以下内容:[python] view plain copydoskey sayhello=echo Hello ...

  3. 多线程---同步函数的锁是this(转载)

    class Ticket implements Runnable { private int tick = 100; Object obj = new Object(); boolean flag = ...

  4. 【编码问题】if,for语句与中文编码

    1. 首先先来说说中文的问题.众所周知,作死的python经常和中文过不去 每次,开头必须声明 # coding: utf-8 或者是 # -*- coding: utf-8  -*- 然而,被坑过的 ...

  5. android资源文件的选取

    Android app项目中,res是用来存放资源文件的,来看看这些文件的创建和选取规则: 系统启动一个apk后,生成UI的过程中,会根据不同的系统配置来匹配.选择相应的资源文件. You shoul ...

  6. javacript参数传递表单验证

    <!doctype html> <html> <head> <meta charset="utf-8"> <style typ ...

  7. 正则匹配 sql语句参数

    List<string> listcommand = new List<string>(); string sql = "update BMDMB set bmdmb ...

  8. pc打开手机站提示切换为手机屏幕

    .turn { position: absolute; width: 100%; height: 100%; left:; top:; background: url(../images.png) c ...

  9. yii2 windows 安装

    Yii是一个高性能的,适用于开发WEB2.0应用的PHP框架. Yii自带了丰富的功能 ,包括MVC,DAO/ActiveRecord,I18N/L10N,缓存,身份验证和基于角色的访问控制,脚手架, ...

  10. 《JavaScript高级程序设计》读书笔记 ---函数

    函数函数对任何语言来说都是一个核心的概念.通过函数可以封装任意多条语句,而且可以在任何地方.任何时候调用执行.ECMAScript 中的函数使用function 关键字来声明,后跟一组参数以及函数体. ...