Simple But Useful Samples About 'grep' Command(简单实用的grep 命令)
命令 简单 39 实用 Command Simple grep
2023-09-11 14:20:42 时间
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
相关文章
- shell脚本--cut命令与awk简单使用
- Linux 简单命令整理
- Linux中什么是块设备 及 lsblk命令的使用
- Maven 电脑每次重启 mvn -v 都显示 不是命令
- mongo数据库命令简单学习
- L15.linux命令每日一练 -- 第二章 文件和目录操作命令 -- chmod、chgrp和umask命令
- linux 查看docker 容器创建时命令——筑梦之路
- top命令简单使用
- [linux]date命令时间戳和时间之间的转换
- 使用hadoop命令rcc生成Record 一个简单的方法来实现自己的定义writable对象
- Linux命令之rz - 批量上传文件,简单易用(转载)
- 批处理命令——choice
- nsenter命令简单介绍
- windows命令之tcping安装和使用
- maven clean install命令报错 Failed to execute goal org.apache.maven.plugins:maven-clean-plugin