Linux环境grep搜索方法记录
1 grep
grep 命令,用来搜索字符串所在位置,可以具体到不同文件,不同行;
在Linux 下,查看命令释义如下
zhaoc@ubuntu2004:~$ grep --help
Usage: grep [OPTION]... PATTERNS [FILE]...
Search for PATTERNS in each FILE.
Example: grep -i 'hello world' menu.h main.c
PATTERNS can contain multiple patterns separated by newlines.Pattern selection and interpretation:-E, --extended-regexp PATTERNS are extended regular expressions-F, --fixed-strings PATTERNS are strings-G, --basic-regexp PATTERNS are basic regular expressions-P, --perl-regexp PATTERNS are Perl regular expressions-e, --regexp=PATTERNS use PATTERNS for matching-f, --file=FILE take PATTERNS from FILE-i, --ignore-case ignore case distinctions in patterns and data--no-ignore-case do not ignore case distinctions (default)-w, --word-regexp match only whole words-x, --line-regexp match only whole lines-z, --null-data a data line ends in 0 byte, not newlineMiscellaneous:-s, --no-messages suppress error messages-v, --invert-match select non-matching lines-V, --version display version information and exit--help display this help text and exitOutput control:-m, --max-count=NUM stop after NUM selected lines-b, --byte-offset print the byte offset with output lines-n, --line-number print line number with output lines--line-buffered flush output on every line-H, --with-filename print file name with output lines-h, --no-filename suppress the file name prefix on output--label=LABEL use LABEL as the standard input file name prefix-o, --only-matching show only nonempty parts of lines that match-q, --quiet, --silent suppress all normal output--binary-files=TYPE assume that binary files are TYPE;TYPE is 'binary', 'text', or 'without-match'-a, --text equivalent to --binary-files=text-I equivalent to --binary-files=without-match-d, --directories=ACTION how to handle directories;ACTION is 'read', 'recurse', or 'skip'-D, --devices=ACTION how to handle devices, FIFOs and sockets;ACTION is 'read' or 'skip'-r, --recursive like --directories=recurse-R, --dereference-recursive likewise, but follow all symlinks--include=GLOB search only files that match GLOB (a file pattern)--exclude=GLOB skip files that match GLOB--exclude-from=FILE skip files that match any file pattern from FILE--exclude-dir=GLOB skip directories that match GLOB-L, --files-without-match print only names of FILEs with no selected lines-l, --files-with-matches print only names of FILEs with selected lines-c, --count print only a count of selected lines per FILE-T, --initial-tab make tabs line up (if needed)-Z, --null print 0 byte after FILE nameContext control:-B, --before-context=NUM print NUM lines of leading context-A, --after-context=NUM print NUM lines of trailing context-C, --context=NUM print NUM lines of output context-NUM same as --context=NUM--color[=WHEN],--colour[=WHEN] use markers to highlight the matching strings;WHEN is 'always', 'never', or 'auto'-U, --binary do not strip CR characters at EOL (MSDOS/Windows)When FILE is '-', read standard input. With no FILE, read '.' if
recursive, '-' otherwise. With fewer than two FILEs, assume -h.
Exit status is 0 if any line (or file if -L) is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.Report bugs to: bug-grep@gnu.org
GNU grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <https://www.gnu.org/gethelp/>
2 搜索方式
2.1 通用格式
我目前使用的命令,通用格式如下
grep <命令选项(可选)> <附加命令项(可选)> <带搜索字符串(支持正则)> <路径(默认为当前路径)>
2.2 当前路径搜索
在当前路径搜索特定字符串,并显示出对应行数
grep -rn "zhaoc"

2.3 指定路径搜索
grep -rn zhaoc ~/11-tools/

2.4 搜索指定文件类型
grep -rin --include=*.h --include=*.cpp foo <可选搜索路径>
实际操作,举例如下:
zhaoc@ubuntu2004:~$ date; grep -rn --include="*h" include ~/gitRepository/UsefulWheels/
2023年 12月 31日 星期日 22:18:09 CST
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/BasicInclude.h:4:#include <iostream>
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/BasicInclude.h:5:#include <string>
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/BasicInclude.h:6:#include <string.h>
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/BasicInclude.h:7:#include <vector>
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/CppWheels_Other.h:4:#include "BasicInclude.h"
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/CppWheels_Other.h:5:#include "Linuxcpptypes.h"
/home/zhaoc/gitRepository/UsefulWheels/LinuxCppInterface/CppWheels_String.h:4:#include "BasicInclude.h"
/home/zhaoc/gitRepository/UsefulWheels/CppInterface/CppWheels_String.h:4:#include <iostream>
/home/zhaoc/gitRepository/UsefulWheels/CppInterface/CppWheels_String.h:5:#include <string>
/home/zhaoc/gitRepository/UsefulWheels/CppInterface/CppWheels_String.h:6:#include <vector>
相关文章:
Linux环境grep搜索方法记录
1 grep grep 命令,用来搜索字符串所在位置,可以具体到不同文件,不同行; 在Linux 下,查看命令释义如下 zhaocubuntu2004:~$ grep --help Usage: grep [OPTION]... PATTERNS [FILE]... Search for PATTERNS in each FI…...
C语言-破解密码
题目描述 密码是我们生活中非常重要的东东,我们的那么一点不能说的秘密就全靠它了。哇哈哈. 接下来渊子要在密码之上再加一套密码,虽然简单但也安全。 假设老王原来一个BBS上的密码为zvbo941987,为了方便记忆,他通过一种算法把这个密码变换…...
ffmpeg 解码文件时的时间戳问题
实时流和普通文件 1 实时流 实时流编码时,我们一般不进行b帧编码,但是文件存储时为了减小大小,会增加b帧,实时流只带了I,P帧,那就会好很多 2 普通文件 很多文件带了b帧,所以要使用解码时间去同…...
Java企业电子招投标系统源代码,支持二次开发,采用Spring cloud框架
在数字化采购领域,企业需要一个高效、透明和规范的管理系统。通过采用Spring Cloud、Spring Boot2、Mybatis等先进技术,我们打造了全过程数字化采购管理平台。该平台具备内外协同的能力,通过待办消息、招标公告、中标公告和信息发布等功能模块…...
[python]基于faster whisper实时语音识别语音转文本
语音识别转文本相信很多人都用过,不管是手机自带,还是腾讯视频都附带有此功能,今天简单说下: faster whisper地址: https://github.com/SYSTRAN/faster-whisperhttps://link.zhihu.com/?targethttps%3A//github.com…...
2023纠结中前行? 2024继续还是放下?
喝下2023年的第一口雪碧,没有想像中的那么期待,甜水,放弃吧;还是吃些水果吧,不行吃块肉、喝两口酒~ 关于生活 挣扎了10几年的一颗牙“终于“掉了,几个月时间都在为新牙努力着;”进了医院就不在…...
原型链补充
1.什么是原型对象 函数的独有属性,他用prototype来表示,可以在函数的prototype上挂载一些公用的属性和方法,供实例化对象来访问。 2.__proto__属性 这个属性每一个对象都有,实例化对象就是通过这个属性,来访问原型对象上的属性和方法的。 3.三者之间的关系 1.在构造函数的原型…...
《Linux Nano命令详解:小而强大的文本编辑器》
《Linux Nano命令详解:小而强大的文本编辑器》 引言: 在Linux系统中,文本编辑是开发和系统管理中不可或缺的一部分。虽然有许多强大的文本编辑器可供选择,但Nano以其简单易用、小巧灵活而备受喜爱。本文将深入探讨Nano命令&…...
系列四、Eureka自我保护
一、Eureka自我保护 1.1、故障现象 保护模式主要用于一组客户端和Eureka Server之间存在网络分区场景下的保护。一旦进入保护模式,Eureka Server将会尝试保护其服务注册表中的信息,不再删除服务注册表中的数据,也就是不会注销任何微服务。如…...
C++回调函数-实操(二)
回调通常通过函数指针、函数对象(仿函数)、Lambda 表达式或者 std::function 来实现。 1、函数指针实现回调 这一方法实现回调比较好记,就记住把函数当作参数传给方法,在方法中调用方法。 #include <iostream>// 回调函数…...
MySQL中常用的用户授权操作
mysql 用户授权 1 )概述 让每个应用程序,单独开一个mysql的用户权限所有mysql用户存储在 mysql库的user表中 2 ) 多种用户授权方式示例 show databases; use mysql;select user, authentication_string, host from mysql.user;-- 创建和删除用户 -- c…...
LabVIEW开发智能火灾自动报警系统
LabVIEW开发智能火灾自动报警系统 系统基于LabVIEW虚拟仪器开发,由火灾报警控制器、感温感烟探测器、手动报警器、声光报警器、ZigBee无线通讯节点以及上位机电脑等组成,展示了LabVIEW在智能化火灾预警与控制方面的应用。该系统通过结合二总线协议和Zig…...
Vagrant使用教程
vmware下载地址:https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html VirtualBox下载地址:https://www.virtualbox.org/wiki/Downloads Vagrant下载地址:https://developer.hashicorp.com/vagrant/install#…...
【Java】ThreadLocal原理与使用场景
ThreadLocal原理: 字段: //ThreadLocal对象的哈希码 private final int threadLocalHashCode nextHashCode();//生成ThreadLocal对象的哈希码时,需要用到该对象,从0开始 private static AtomicInteger nextHashCode new Atomic…...
软件测试/测试开发丨Linux进阶命令(curl、jq)
1、 curl 接口请求 curl是一个发起请求数据给服务器的工具curl支持的协议FTP、FTPS、HTTP、HTTPS、TFTP、SFTP、Gopher、SCP、Telnet、DICT、FILE、LDAP、LDAPS、IMAP、POP3、SMTP和RTSPcurl是一个非交互的工具 2、 curl 发起 get 请求 -G:使用get请求-d…...
模式识别与机器学习-SVM(带软间隔的支持向量机)
SVM(带软间隔的支持向量机) 软间隔思想的由来软间隔的引入 谨以此博客作为复习期间的记录。 软间隔思想的由来 在上一篇博客中,回顾了线性可分的支持向量机,但在实际情况中,很少有完全线性可分的情况,大部分线性可分…...
CentOS 7 firewalld+ipset+定时任务防御ssh暴力破解——筑梦之路
对于暴露在公网上的linux服务器,很容易被暴力破解登陆,为了增强服务器的安全性,因此对于ssh安全加固是很有必要的,这里主要介绍centos7 系统如何使用ipsetfirewalld定时任务来对ssh服务进行安全加固。 定义firewalld ipset fire…...
ElasticSearch的RestClient结合Sniffer提高可用性
一、背景 由于要安装分词器插件,所以需要重启ElasticSearch集群以使得新安装的插件生效 但是在重启集群的过程中,服务端代码却出现了大量错误,如下所示 java.net.ConnectException: Connection refused at org.elasticsearch.client.R…...
【网络面试(2)】DNS原理-域名和IP地址的查询转换
从上一篇博客我们得知浏览器是如何生成了HTTP消息了,但是浏览器作为应用程序,是不具备向网络中发送请求的能力,而是需要委托给操作系统的内核协议栈来发送请求。在委托协议栈之前,浏览器还要做的一件事情就是将域名转换为IP地址。…...
【PHP】函数array_intersect、array_diff:从数组中取出、去除指定的几个键值
1.从数组中取出 :array_intersect 要从数组中取出指定的几个键值,可以使用 array_intersect_key 函数。以下是一个示例: $array [name > John,age > 30,email > johnexample.com,city > New York ];$keys [name, email];$resu…...
Linux链表操作全解析
Linux C语言链表深度解析与实战技巧 一、链表基础概念与内核链表优势1.1 为什么使用链表?1.2 Linux 内核链表与用户态链表的区别 二、内核链表结构与宏解析常用宏/函数 三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势5.1 插入效率5.2 安全…...
UDP(Echoserver)
网络命令 Ping 命令 检测网络是否连通 使用方法: ping -c 次数 网址ping -c 3 www.baidu.comnetstat 命令 netstat 是一个用来查看网络状态的重要工具. 语法:netstat [选项] 功能:查看网络状态 常用选项: n 拒绝显示别名&#…...
docker 部署发现spring.profiles.active 问题
报错: org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...
python报错No module named ‘tensorflow.keras‘
是由于不同版本的tensorflow下的keras所在的路径不同,结合所安装的tensorflow的目录结构修改from语句即可。 原语句: from tensorflow.keras.layers import Conv1D, MaxPooling1D, LSTM, Dense 修改后: from tensorflow.python.keras.lay…...
TSN交换机正在重构工业网络,PROFINET和EtherCAT会被取代吗?
在工业自动化持续演进的今天,通信网络的角色正变得愈发关键。 2025年6月6日,为期三天的华南国际工业博览会在深圳国际会展中心(宝安)圆满落幕。作为国内工业通信领域的技术型企业,光路科技(Fiberroad&…...
Unity中的transform.up
2025年6月8日,周日下午 在Unity中,transform.up是Transform组件的一个属性,表示游戏对象在世界空间中的“上”方向(Y轴正方向),且会随对象旋转动态变化。以下是关键点解析: 基本定义 transfor…...
渗透实战PortSwigger靶场:lab13存储型DOM XSS详解
进来是需要留言的,先用做简单的 html 标签测试 发现面的</h1>不见了 数据包中找到了一个loadCommentsWithVulnerableEscapeHtml.js 他是把用户输入的<>进行 html 编码,输入的<>当成字符串处理回显到页面中,看来只是把用户输…...
多元隐函数 偏导公式
我们来推导隐函数 z z ( x , y ) z z(x, y) zz(x,y) 的偏导公式,给定一个隐函数关系: F ( x , y , z ( x , y ) ) 0 F(x, y, z(x, y)) 0 F(x,y,z(x,y))0 🧠 目标: 求 ∂ z ∂ x \frac{\partial z}{\partial x} ∂x∂z、 …...
IP选择注意事项
IP选择注意事项 MTP、FTP、EFUSE、EMEMORY选择时,需要考虑以下参数,然后确定后选择IP。 容量工作电压范围温度范围擦除、烧写速度/耗时读取所有bit的时间待机功耗擦写、烧写功耗面积所需要的mask layer...
SDU棋界精灵——硬件程序ESP32实现opus编码
一、 音频处理框架 该项目基于Espressif的音频处理框架构建,核心组件包括 ESP-ADF 和 ESP-SR,以下是完整的音频处理框架实现细节: 1.核心组件 (1) 音频前端处理 (AFE - Audio Front-End) main/components/audio_pipeline/afe_processor.c功能: 声学回声…...
