1,安装命令:

install kitty:

curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin

install repgrep:

    curl -LO  https://github.com/BurntSushi/ripgrep/releases/download/12.1.1/ripgrep_12.1.1_amd64.deb
    sudo dpkg -i ripgrep_12.1.1_amd64.deb

2,新建配置文件:

touch .config/kitty/open-actions.conf

3,编辑配置文件:

vi .config/kitty/open-actions.conf

4,拷贝下面配置中一种(VIM或gedit)并粘贴到3打开的open-actions.conf文件中,保存并退出。

VIM方式:

# Open any file with a fragment in vim, fragments are generated
# by the hyperlink_grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay vim +${FRAGMENT} ${FILE_PATH}
# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay ${EDITOR} ${FILE_PATH}

gedit方式:

# Open any file with a fragment in gedit, fragments are generated
# by the hyperlink_grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay gedit +${FRAGMENT} ${FILE_PATH}
# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay ${EDITOR} ${FILE_PATH}

5,打开kitty终端

 .local/kitty.app/bin/kitty 

6, kitty终端输入要搜索内容

kitty +kitten hyperlinked_grep UFC

点击搜索到的关键词,波浪显示并自动跳转打开文件,光标显示在对应行(我用gedit方式):

7,kitty终端内复制粘贴是ctrl+shift+c/ctrl+shift+v,记住多了个shift。

还可以参考以下链接

Hyperlinked grep - kitty https://sw.kovidgoyal.net/kitty/kittens/hyperlinked_grep/?highlight=grep

Hyperlinked grep - kitty

Hyperlinked grep

This kitten allows you to search your files using ripgrep and open the results directly in your favorite editor in the terminal, at the line containing the search result, simply by clicking on the result you want.

New in version 0.19.0.

To set it up, first create ~/.config/kitty/open-actions.conf with the following contents:

# Open any file with a fragment in vim, fragments are generated
# by the hyperlink_grep kitten and nothing else so far.
protocol file
fragment_matches [0-9]+
action launch --type=overlay vim +${FRAGMENT} ${FILE_PATH}
# Open text files without fragments in the editor
protocol file
mime text/*
action launch --type=overlay ${EDITOR} ${FILE_PATH}

Now, run a search with:

kitty +kitten hyperlinked_grep something

Hold down the Ctrl+Shift keys and click on any of the result lines, to open the file in vim at the matching line. If you use some editor other than vim, you should adjust the open-actions.conf file accordingly.

Finally, add an alias to your shell’s rc files to invoke the kitten as hg:

alias hg="kitty +kitten hyperlinked_grep"

You can now run searches with:

hg some-search-term

If you want to enable completion, for the kitten, you can delegate completion to rg. How to do that varies based on the shell:

Instead of using an alias, create a simple wrapper script named hg somewhere in your PATH:

#!/bin/sh
exec kitty +kitten hyperlinked_grep "$@"

Then, add the following to .zshrc:

compdef _rg hg

To learn more about kitty’s powerful framework for customizing URL click actions, see here.

By default, this kitten adds hyperlinks for several parts of ripgrep output: the per-file header, match context lines, and match lines. You can control which items are linked with a --kitten hyperlink flag. For example, --kitten hyperlink=matching_lines will only add hyperlinks to the match lines. --kitten hyperlink=file_headers,context_lines will link file headers and context lines but not match lines. --kitten hyperlink=none will cause the command line to be passed to directly to rg so no hyperlinking will be performed. --kitten hyperlink may be specified multiple times.

Hopefully, someday this functionality will make it into some upstream grep program directly removing the need for this kitten.

While you can pass any of ripgrep’s comand line options to the kitten and they will be forwarded to rg, do not use options that change the output formatting as the kitten works by parsing the output from ripgrep.

linux最快的文本搜索神器ripgrep(grep的最好代替者)

这篇文章主要介绍了linux最快的文本搜索神器ripgrep(grep的最好代替者),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

说到文本搜索工具,大家一定会知道 grep, 它是 linux 最有用并最常用的工具之一。
但如果要再一个大的工程项目中搜索某个关键词,大家也一定知道它比较耗时。
所以就有了很多替代工具,之前最出名的是 Ack,Ag
而最近又有了新的替代者 Ripgrep, 这个工具和 Ack/Ag 一样都使用了多线程的方法,但 rg 比它们更快

ripgrep 是一个以行为单位的搜索工具, 它根据提供的 pattern 递归地在指定的目录里搜索。它是由 Rust 语言写成,相较与同类工具,它的特点就是无与伦比地快。
几个特点如下:

  • 自动递归搜索 (grep 需要-R)
  • 自动忽略.gitignore 中的文件以及 2 进制文件
  • 可以搜索指定文件类型(rg -tpy foo限定 python 文件, rg -Tjs foo排除 js 文件)
  • 支持大部分 grep 的 feature(常用的都有)
  • 支持各种文件编译(UTF-8, UTF-16, latin-1, GBK, EUC-JP, Shift_JIS 等等)
  • 支持搜索常见压缩文件(gzip, xz, lzma, bzip2, lz4)
  • 自动高亮匹配的结果
  • 更少的命令名称 rg (grep 是四个字符)
  • 不支持多行搜索和花哨的正则

安装 ripgrep

先安装 RUST

1

curl https://sh.rustup.rs -sSf | sh

然后一路 enter 就好了

用 RUST 安装 rigpre

1

2

3

4

git clone https://github.com/BurntSushi/ripgrep

cd ripgrep

cargo build --release

cp ./target/release/rg /usr/local/bin/

最后一步根据你的情况把它放到某个在 PATH 里的路径里

搜索结果展示

用法总体格式

1

2

3

4

5

6

USAGE:

  rg [OPTIONS] PATTERN [PATH ...]

  rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]

  rg [OPTIONS] --files [PATH ...]

  rg [OPTIONS] --type-list

  command | rg [OPTIONS] PATTERN

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

ARGS:

  <PATTERN>

      A regular expression used for searching. To match a pattern beginning with a

      dash, use the -e/--regexp flag.

      For example, to search for the literal '-foo', you can use this flag:

        rg -e -foo

      You can also use the special '--' delimiter to indicate that no more flags

      will be provided. Namely, the following is equivalent to the above:

        rg -- -foo

  <PATH>...

      A file or directory to search. Directories are searched recursively. Paths specified on

      the command line override glob and ignore rules.

optionsDescriptionother
-A, --after-context <NUM>显示匹配内容后的<NUM>行会覆盖--context
-B, --before-context <NUM>显示匹配内容前的<NUM>行会覆盖--context
-b, --byte-offset显示匹配内容在文件中的字节偏移和-o 一起使用,只打印偏移
-s, --case-sensitive大小写敏感会覆盖-i(ignore case), -S(smart case)
--color <WHEN>什么时候使用颜色,默认 auto如果--vimgre 被使用,那么默认值是 never
可选项有: never, auto, always, ansi
--colors <COLOR_SPEC>...设定输出颜色:color: red, blue, green, cyan
{type}:{attribute}:{value}magenta, yellow, white, black
{type}: path, line, column, matchstyle: nobold, bold, nointense
{attribute}: fg, bg, styleintense, nounderline, underline
{value}: a color or a text styleExample:
{type}:none会清空{type}的颜色设定rg --colors 'match:fg:magenta' --colors 'line:bg:yellow' foo
扩展颜色集可以被{value}使用,如果终端支持 ANSI color
描述方法是'x'(256-color) 或 'x,x,x'(24-bit true color)
x 是 0-255 之间的数值,默认是 10 进制, 0x 前缀是 16 进制
比如: rg --colors 'match:bg:0,128,255'
或者等价的:rg --colors 'match:bg:0x0,0x80,0xFF'
在使用 extended color code 时 intense 和 nointense 是无效的
--column第一次匹配所在列数(从 1 开始)能够被--no-column 取消掉
-C, --context <NUM>显示匹配内容的前面和后面的<NUM>行它会覆盖-B 和-A 选项
--context-separator <SEPARATOR>在输出中用来分隔非连续的行x7F 或t 可被使用,默认是--
-c, --count只显示匹配的行数如果只有一个文件给 ripgrep,那只打印匹配行数
可以用--with-filename 来强制打印文件名
它会覆盖--count-matches 选项
--count-matches只显示匹配的次数可以用--with-file 来强制在只有一个文件时也输出文件名
--debug显示调试信息
--dfa-size-limit <NUM+SUFFIX?>regex DFA 的上限, 默认 10M
-E, --encoding <ENCODING>描述文本编码, 默认是 autoEncoding Standard
-f, --file <PATTERNFILE>...从文件中读入 pattern, 一行一 pattern可以被多次使用或和-e 一起组合使用,所以有组合会被匹配
--files打印所有将被搜索的文件rg <options> --files [PATH...]方式使用,不能加 pattern
-l, --files-with-matches只打印有匹配的文件名覆盖--files-without-match
--files-without-match只打印无匹配的文件名覆盖 --file-with-matches
-F, --fixed-strings把 pattern 当成常规文字而非 regex可以用--no-fixed-strings 来禁止这个选项
-L, --follow会递归搜索链接,默认关闭可以用--no-follow 来关闭
-g, --glob <GLOB>...通配符文件或文件夹,可以用!来取反可以多次使用, 会匹配.gitignore 的通配符规则
-h, --help打印帮助信息
--heading打印文件名到匹配内容的上方而不是同一行这是默认行为,可以用--no-heading 来关闭
--hidden搜索隐藏文件和文件夹默认忽略, 可用--no-hidden 关闭
--iglob <GLOB>...同--glob, 但这个大小写不敏感
-i, --ignore-casepattern 大小写不敏感可通过-s/--case-sensitive 或-S/--smart-case 覆盖这个选项
--ignore-file <PATH>...忽略路径,格式同.gitignore, 可多个多个--ignore-file 标记时,后面优先级高
在命令上时,使用-g 来达到同样效果
-v, --invert-match反向匹配
-n, --line-number显示文件行数,默认打开
-x, --line-regexp只显示整行都匹配 pattern 的行会覆盖--word-regexp
-M, --max-columns <NUM>不打印长于<NUM>列的匹配行
-m, --max-count <NUM>限制一个文件最多<NUM>行匹配
--max-depth <NUM>限制文件夹递归搜索深度rg --max-depth 0 dir/不执行任何搜索
--max-filesize <NUM+SUFFIX?>忽略大于<NUM>byte 的文件suffix 可以是 K, M,G, 默认是 byte
--mmap尽量使用 memory maps, 默认行为目前它不支持所有选项, 用--no-mmap 来关闭
--no-config不读取 conf 文件, 忽略 RIPGREP_CONFIG_PATH
--no-filename不要打印匹配文件名
--no-heading在每个匹配行前都打印文件名
--no-ignore取消 ignore 文件,如.gitignore, .ignore可以用--ignore 关闭
--no-ignore-global取消对全局的 ignore 文件读取如$HOME/.config/git/ignore
--no-ignore-messages取消解析.ignroe, .gitignore 文件相关错误可通过--ignore-messages 关闭
--no-ignore-parent不读取父文件夹里的.gitignore, .ignore 文件可通过 --ignore-parent 关闭
--no-ignore-vcs只全能.ignore 文件可通过--ignore-vcs 关闭
-N, --no-line-number不打印匹配行数
--no-messages不打印打开和读取文件相关错误
-0, --null在打印的文件路径后加一个 NUL 字符对于 xargs 非常有用
-o, --only-matching只打印匹配的内容,而不是整行
--passthru打印匹配和不匹配的行
--path-separator <SEPARATOR>路径分隔符,在 linux 上默认是/
--pre <COMMAND>用<COMMAND>处理文件,并将结果给 rg可能有巨大的性能惩罚
例如
case "$1" in
*.pdf)
exec pdftotext "$1" -
;;
*)
case $(file "$1") in
_Zstandard_)
exec pzstd -cdq
;;
*)
exec cat
;;
esac
;;
esac
-p, --pretty--color always --heading --line-number
-q, --quiet不打印到 stdout, 如果匹配发现,停止 rg当 rg 用于 exit 代码时非常有用
--regex-size-limit <NUM+SUFFIX?>编译 regex 的上限
-e, --regexp <PATTERN>...使用正则来匹配可多次使用这个选项,打印匹配任何 pattern 的行
可以用于搜索-开头的 pattern,如rg -e -foo
-r, --replace <REPLACEMENT_TEXT>用相应文件代替匹配内容打印出来组序号($5)可以被使用
-z, --search-zip在 gz,bz2,xz,lzma,lz4 文件类型中搜索可通过--no-search-zip 关闭
-S, --smart-case如果全小写,则大小写不敏感,否则敏感可通过-s/--case-sensitive 和-i/--ignore-case 关闭
--sort-files根据文件路径排序输出结果会关闭并行搜索线程
--stats打印出统计结果
-a, --text搜索二进制文件可通过--no-text 关闭
-j, --threads <NUM>大约使用的线程数
-t, --type <TYPE>...只搜索某种文件类型可通过--type-lsit 来列出支持的文件类型
--type-add <TYPE_SPEC>...添加文件类型rg --type-add 'foo:*.foo' -tfoo PATTERN
也可以用来创建某种包含多种文件类型的规则--type-add 'src:include:cpp,py,md'
--type-clear <TYPE>...清除默认的文件类型
--type-list列出所有内置文件类型
-T, --type-not <TYPE>...不要搜索某种文件类型
-u, --unrestricted-u 搜索.gitignore 里的文件, -uu 搜索隐藏文件-uuu 搜索二进制文件
-V, --version打印版本信息
--vimgrep每一次匹配打印一行一行有多次匹配会打印多行
-H, --with-filename打印匹配的文件路径,默认可通过--no-filename 关闭
-w, --word-regexp把 pattern 作为单独单词匹配,与< >等价

1

$ rg 'name' ./

搜索name为独立单词的内容(-w), 相当于<pattern>

1

$ rg -w 'name' ./

只打印包含匹配内容的文件名(-l)

1

2

3

$ rg -w 'name' ./ -l

src/cpp/epoll_server.cpp

src/cpp/uart_xtor.cpp

只搜索cpp文件(-t), 可以用-T来不搜索某种类型文件

1

$ rg -w 'name' ./ -tcpp

正则搜索(-e)

1

$ rg -e "sa.*port" ./ -tcpp

显示匹配内容及上下各两行(-C), -A/-B类似

1

$ rg -e "sa.*port" ./ -tcpp -C2

显示不含"debug"的行(-v)

1

$ rg -v "debug" -tcpp ./

只显示匹配部分(-o)

1

$ rg -e "if.*debug" ./ -tcpp -o

忽略大小写(-i)

1

$ rg -ie "if.*debug" ./ -tcpp -o

把pattern当成常量字符(-F), 像.(){}*+不需要escape,如果要搜索的字符是以-开头,那么要用--来作为分隔符,或者用rg -e "-foo"

1

rg -F "i++)" ./ -tcpp

打印所有将被搜索的文件 --files

1

rg --files

输出内置识别文件类型

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

$ rg --type-list

agda: *.agda, *.lagda

aidl: *.aidl

amake: *.bp, *.mk

asciidoc: *.adoc, *.asc, *.asciidoc

asm: *.S, *.asm, *.s

ats: *.ats, *.dats, *.hats, *.sats

avro: *.avdl, *.avpr, *.avsc

awk: *.awk

bazel: *.bzl, BUILD, WORKSPACE

bitbake: *.bb, *.bbappend, *.bbclass, *.conf, *.inc

bzip2: *.bz2

c: *.H, *.c, *.cats, *.h

cabal: *.cabal

cbor: *.cbor

ceylon: *.ceylon

clojure: *.clj, *.cljc, *.cljs, *.cljx

cmake: *.cmake, CMakeLists.txt

coffeescript: *.coffee

config: *.cfg, *.conf, *.config, *.ini

cpp: *.C, *.H, *.cc, *.cpp, *.cxx, *.h, *.hh, *.hpp, *.hxx, *.inl

creole: *.creole

crystal: *.cr, Projectfile

cs: *.cs

csharp: *.cs

cshtml: *.cshtml

css: *.css, *.scss

csv: *.csv

cython: *.pyx

d: *.d

dart: *.dart

dhall: *.dhall

docker: *Dockerfile*

elisp: *.el

elixir: *.eex, *.ex, *.exs

elm: *.elm

erlang: *.erl, *.hrl

fidl: *.fidl

fish: *.fish

fortran: *.F, *.F77, *.F90, *.F95, *.f, *.f77, *.f90, *.f95, *.pfo

fsharp: *.fs, *.fsi, *.fsx

gn: *.gn, *.gni

go: *.go

groovy: *.gradle, *.groovy

gzip: *.gz

h: *.h, *.hpp

haskell: *.c2hs, *.cpphs, *.hs, *.hsc, *.lhs

hbs: *.hbs

hs: *.hs, *.lhs

html: *.ejs, *.htm, *.html

idris: *.idr, *.lidr

java: *.java, *.jsp

jinja: *.j2, *.jinja, *.jinja2

jl: *.jl

js: *.js, *.jsx, *.vue

json: *.json, composer.lock

jsonl: *.jsonl

julia: *.jl

jupyter: *.ipynb, *.jpynb

kotlin: *.kt, *.kts

less: *.less

license: *[.-]LICEN[CS]E*, AGPL-*[0-9]*, APACHE-*[0-9]*, BSD-*[0-9]*, CC-BY-*, COPYING, COPYING[.-]*, COPYRIGHT, COPYRIGHT[.-]*, EULA, EULA[.-]*, GFDL-*[0-9]*, GNU-*[0-9]*, GPL-*[0-9]*, LGPL-*[0-9]*, LICEN[CS]E, LICEN[CS]E[.-]*, MIT-*[0-9]*, MPL-*[0-9]*, NOTICE, NOTICE[.-]*, OFL-*[0-9]*, PATENTS, PATENTS[.-]*, UNLICEN[CS]E, UNLICEN[CS]E[.-]*, agpl[.-]*, gpl[.-]*, lgpl[.-]*, licen[cs]e, licen[cs]e.*

lisp: *.el, *.jl, *.lisp, *.lsp, *.sc, *.scm

log: *.log

lua: *.lua

lz4: *.lz4

lzma: *.lzma

m4: *.ac, *.m4

make: *.mak, *.mk, GNUmakefile, Gnumakefile, Makefile, gnumakefile, makefile

man: *.[0-9][cEFMmpSx], *.[0-9lnpx]

markdown: *.markdown, *.md, *.mdown, *.mkdn

matlab: *.m

md: *.markdown, *.md, *.mdown, *.mkdn

mk: mkfile

ml: *.ml

msbuild: *.csproj, *.fsproj, *.proj, *.props, *.targets, *.vcxproj

nim: *.nim

nix: *.nix

objc: *.h, *.m

objcpp: *.h, *.mm

ocaml: *.ml, *.mli, *.mll, *.mly

org: *.org

pdf: *.pdf

perl: *.PL, *.perl, *.pl, *.plh, *.plx, *.pm, *.t

php: *.php, *.php3, *.php4, *.php5, *.phtml

pod: *.pod

protobuf: *.proto

ps: *.cdxml, *.ps1, *.ps1xml, *.psd1, *.psm1

puppet: *.erb, *.pp, *.rb

purs: *.purs

py: *.py

qmake: *.prf, *.pri, *.pro

r: *.R, *.Rmd, *.Rnw, *.r

rdoc: *.rdoc

readme: *README, README*

rst: *.rst

ruby: *.gemspec, *.rb, .irbrc, Gemfile, Rakefile

rust: *.rs

sass: *.sass, *.scss

scala: *.sbt, *.scala

sh: *.bash, *.bashrc, *.csh, *.cshrc, *.ksh, *.kshrc, *.sh, *.tcsh, *.zsh, .bash_login, .bash_logout, .bash_profile, .bashrc, .cshrc, .kshrc, .login, .logout, .profile, .tcshrc, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, bash_login, bash_logout, bash_profile, bashrc, profile, zlogin, zlogout, zprofile, zshenv, zshrc

smarty: *.tpl

sml: *.sig, *.sml

soy: *.soy

spark: *.spark

sql: *.psql, *.sql

stylus: *.styl

sv: *.h, *.sv, *.svh, *.v, *.vg

svg: *.svg

swift: *.swift

swig: *.def, *.i

systemd: *.automount, *.conf, *.device, *.link, *.mount, *.path, *.scope, *.service, *.slice, *.socket, *.swap, *.target, *.timer

taskpaper: *.taskpaper

tcl: *.tcl

tex: *.bib, *.cls, *.ltx, *.sty, *.tex

textile: *.textile

tf: *.tf

toml: *.toml, Cargo.lock

ts: *.ts, *.tsx

twig: *.twig

txt: *.txt

vala: *.vala

vb: *.vb

verilog: *.sv, *.svh, *.v, *.vh

vhdl: *.vhd, *.vhdl

vim: *.vim

vimscript: *.vim

webidl: *.idl, *.webidl, *.widl

wiki: *.mediawiki, *.wiki

xml: *.xml, *.xml.dist

xz: *.xz

yacc: *.y

yaml: *.yaml, *.yml

zsh: *.zsh, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, zlogin, zlogout, zprofile, zshenv, zshrc

ripgrep的搜索速度真是快的飞起来,在浏览代码时对我的帮助非常大。我相信它对于每一个码农的价值都是无限大的,特别是结合FZF之后。
唯一的弱点是对正则的支持,但这是一个取舍,如果采用如PCRE那样的库的话,一定会极大影响速度。

说到文本搜索工具,大家一定会知道 grep, 它是 linux 最有用并最常用的工具之一。但如果要再一个大的工程项目中搜索某个关键词,大家也一定知道它比较耗时。所以就有了很多替代工具,之前最出名的是 Ack,Ag而最近又有了新的替代者 Ripgrep, 这个工具和 Ack/Ag 一样都使用了多线程的方法,但 rg 比它们更快。 kitty是一个免费的开源 图形处理单元(GPU) 加速[2] [3] 终端仿真器,适用于Linux和macOS,专注于性能和功能。kitty 是用C和Python编程语言混合编写的,它是少数支持 GPU 和Alacritty的终端仿真器之一。kitty 与另一个程序 KiTTY 同名,它是用于Microsoft Windows的PuTTY的一个分支。[4] 显示图像:安装ImageMagick后,添加到 .bashrc 交互式 Unicode 字符输入 ( ctrl+shift+u),按名称
ripgrep是开源社区正在进行的 RIIR(用 Rust 重写)努力的一个优秀成果。,它旨在成为经典grep 命令的高级替代品。 使用 ripgrep 的语法如下: rg <pattern> [files/directories] 使用 ripgrep,无需提及文件名。如果未提供文件名,则搜索所有文件,如果您不知道哪个文件包含您搜索的模式,这将非常有用。 您也可以使用 grep 搜索所有文件,但 ripgrep 无需任何额外努力即可完成。 什么是 ripgrep? ripgrep是一个递归正
abc    搜索名字为abc的文件和文件夹 123 abc    搜索文件名包含123和abc的文件和文件夹 *.jpg    搜索jpg后缀文件。*可以不写,*.jpg或.jpg都可以。 指定路径搜索: F:\TDDOWNLOAD\ abc    在F:\TDDOWNLOAD\目录下搜索包含abc字符的文件及文件夹 abc F:\TDDOWNLOAD\    目录放在文件名的...
grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。 -a 不要忽略二进制数据。 -A 除了显示符合范本样式的那一行之外,并显示该行之后的内容。 -b 在显示符合范本样式的那一行之外,并显示该行之前