is a powerful text search tool that can use regular expressions to search for text and print matching lines.
I often use it to find strings such as:
grep -rn "字符串" .
Recursively finds the "string" in all files in the current directory and the line in which it is marked.
Here's a look at the specific parameters:
grep [-acinv] [--color=auto] ‘搜寻字符串‘ filename 选项参数: -a :将 binary 档案以 text 档案方式搜寻数据 -c :计算找刡 ‘搜寻字符串‘ 次数 -i :忽略大小写 -n :输出行号 -v :反向选择,亦即显示出没有 ‘搜寻字符串‘ 内容癿那一行! --color=auto :可以将找刡癿关键词部分加上颜色癿显示! -A :后面可加数字,为 after 癿意思,除了列出该行外,后续的 n 行也列出; -B :后面可加数字,为 befer 癿意思,除了列出该行外,前面的 n 行也列出;
GREP supports only the underlying regular notation, and if you want to extend the regular, use Egrep or GREP-E.
The basic regular notation is summarized as follows:
^word:查找字符串(word)在行首 grep -n ‘^word‘ filename word$: 查找字符串(word)在行末 grep -n ‘word$‘ filename . : 任意字符 \ : 转译 *:前面字符 0 到 任意多个 [] : 字符集合 [n1-n2] : 范围 如[0-9] [^]: 字符取反,就是不能是里面的字符 \{n,m\}: 出现n到m次
The extension of the regular presentation is summarized as follows:
+ :一个或者一个以上 ? :零个或者一个 | : 或 () : 群组 egrep -n ‘g(la|oo)d‘ filename 找出 glad 或者 good 两个字符串 ()+: 群组出现一次或者多次
grep also has a lot of advanced usage, please be interested in the replenishment, I only listed the basic common usage.
Shell–grep Common usage