芮城网站建设,企业邮箱注册申请官网,重庆建设厅的网站首页,有没有资源可以在线观看前言说到文本搜索工具#xff0c;大家一定会知道 grep, 它是 linux 最有用并最常用的工具之一。但如果要再一个大的工程项目中搜索某个关键词#xff0c;大家也一定知道它比较耗时。所以就有了很多替代工具#xff0c;之前最出名的是 Ack#xff0c;Ag而最近又有了新的替代…前言说到文本搜索工具大家一定会知道 grep, 它是 linux 最有用并最常用的工具之一。但如果要再一个大的工程项目中搜索某个关键词大家也一定知道它比较耗时。所以就有了很多替代工具之前最出名的是 AckAg而最近又有了新的替代者 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先安装 RUSTcurl https://sh.rustup.rs -sSf | sh然后一路 enter 就好了用 RUST 安装 rigpregit clone https://github.com/BurntSushi/ripgrepcd ripgrepcargo build --releasecp ./target/release/rg /usr/local/bin/最后一步根据你的情况把它放到某个在 PATH 里的路径里使用搜索结果展示用法总体格式USAGE:rg [OPTIONS] PATTERN [PATH ...]rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]rg [OPTIONS] --files [PATH ...]rg [OPTIONS] --type-listcommand | rg [OPTIONS] PATTERN输入参数ARGS:A regular expression used for searching. To match a pattern beginning with adash, use the -e/--regexp flag.For example, to search for the literal -foo, you can use this flag:rg -e -fooYou can also use the special -- delimiter to indicate that no more flagswill be provided. Namely, the following is equivalent to the above:rg -- -foo...A file or directory to search. Directories are searched recursively. Paths specified onthe command line override glob and ignore rules.optionsDescriptionother-A, --after-context 显示匹配内容后的行会覆盖--context-B, --before-context 显示匹配内容前的行会覆盖--context-b, --byte-offset显示匹配内容在文件中的字节偏移和-o 一起使用只打印偏移-s, --case-sensitive大小写敏感会覆盖-i(ignore case), -S(smart case)--color 什么时候使用颜色默认 auto如果--vimgre 被使用那么默认值是 never可选项有 never, auto, always, ansi--colors ...设定输出颜色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 显示匹配内容的前面和后面的行它会覆盖-B 和-A 选项--context-separator 在输出中用来分隔非连续的行x7F 或t 可被使用默认是---c, --count只显示匹配的行数如果只有一个文件给 ripgrep那只打印匹配行数可以用--with-filename 来强制打印文件名它会覆盖--count-matches 选项--count-matches只显示匹配的次数可以用--with-file 来强制在只有一个文件时也输出文件名--debug显示调试信息--dfa-size-limit regex DFA 的上限 默认 10M-f, --file ...从文件中读入 pattern, 一行一 pattern可以被多次使用或和-e 一起组合使用所以有组合会被匹配--files打印所有将被搜索的文件以rg --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 ...通配符文件或文件夹可以用!来取反可以多次使用 会匹配.gitignore 的通配符规则-h, --help打印帮助信息--heading打印文件名到匹配内容的上方而不是同一行这是默认行为可以用--no-heading 来关闭--hidden搜索隐藏文件和文件夹默认忽略, 可用--no-hidden 关闭--iglob ...同--glob, 但这个大小写不敏感-i, --ignore-casepattern 大小写不敏感可通过-s/--case-sensitive 或-S/--smart-case 覆盖这个选项--ignore-file ...忽略路径格式同.gitignore, 可多个多个--ignore-file 标记时后面优先级高在命令上时使用-g 来达到同样效果-v, --invert-match反向匹配-n, --line-number显示文件行数默认打开-x, --line-regexp只显示整行都匹配 pattern 的行会覆盖--word-regexp-M, --max-columns 不打印长于列的匹配行-m, --max-count 限制一个文件最多行匹配--max-depth 限制文件夹递归搜索深度rg --max-depth 0 dir/不执行任何搜索--max-filesize 忽略大于byte 的文件suffix 可以是 K, MG, 默认是 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 路径分隔符在 linux 上默认是/--pre 用处理文件并将结果给 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 编译 regex 的上限-e, --regexp ...使用正则来匹配可多次使用这个选项打印匹配任何 pattern 的行可以用于搜索-开头的 pattern如rg -e -foo-r, --replace 用相应文件代替匹配内容打印出来组序号($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 大约使用的线程数-t, --type ...只搜索某种文件类型可通过--type-lsit 来列出支持的文件类型--type-add ...添加文件类型如rg --type-add foo:*.foo -tfoo PATTERN也可以用来创建某种包含多种文件类型的规则--type-add src:include:cpp,py,md--type-clear ...清除默认的文件类型--type-list列出所有内置文件类型-T, --type-not ...不要搜索某种文件类型-u, --unrestricted-u 搜索.gitignore 里的文件, -uu 搜索隐藏文件-uuu 搜索二进制文件-V, --version打印版本信息--vimgrep每一次匹配打印一行一行有多次匹配会打印多行-H, --with-filename打印匹配的文件路径默认可通过--no-filename 关闭-w, --word-regexp把 pattern 作为单独单词匹配与 等价实例展示实例一$ rg name ./实例二搜索name为独立单词的内容(-w), 相当于$ rg -w name ./实例三只打印包含匹配内容的文件名(-l)$ rg -w name ./ -lsrc/cpp/epoll_server.cppsrc/cpp/uart_xtor.cpp实例四只搜索cpp文件(-t), 可以用-T来不搜索某种类型文件$ rg -w name ./ -tcpp实例五正则搜索(-e)$ rg -e sa.*port ./ -tcpp实例六显示匹配内容及上下各两行(-C), -A/-B类似$ rg -e sa.*port ./ -tcpp -C2实例七显示不含debug的行(-v)$ rg -v debug -tcpp ./实例八只显示匹配部分(-o)$ rg -e if.*debug ./ -tcpp -o实例九忽略大小写(-i)$ rg -ie if.*debug ./ -tcpp -o实例十把pattern当成常量字符(-F), 像.(){}*不需要escape如果要搜索的字符是以-开头那么要用--来作为分隔符或者用rg -e -foorg -F i) ./ -tcpp实例十一打印所有将被搜索的文件 --filesrg --files实例十二输出内置识别文件类型$ rg --type-listagda: *.agda, *.lagdaaidl: *.aidlamake: *.bp, *.mkasciidoc: *.adoc, *.asc, *.asciidocasm: *.S, *.asm, *.sats: *.ats, *.dats, *.hats, *.satsavro: *.avdl, *.avpr, *.avscawk: *.awkbazel: *.bzl, BUILD, WORKSPACEbitbake: *.bb, *.bbappend, *.bbclass, *.conf, *.incbzip2: *.bz2c: *.H, *.c, *.cats, *.hcabal: *.cabalcbor: *.cborceylon: *.ceylonclojure: *.clj, *.cljc, *.cljs, *.cljxcmake: *.cmake, CMakeLists.txtcoffeescript: *.coffeeconfig: *.cfg, *.conf, *.config, *.inicpp: *.C, *.H, *.cc, *.cpp, *.cxx, *.h, *.hh, *.hpp, *.hxx, *.inlcreole: *.creolecrystal: *.cr, Projectfilecs: *.cscsharp: *.cscshtml: *.cshtmlcss: *.css, *.scsscsv: *.csvcython: *.pyxd: *.ddart: *.dartdhall: *.dhalldocker: *Dockerfile*elisp: *.elelixir: *.eex, *.ex, *.exselm: *.elmerlang: *.erl, *.hrlfidl: *.fidlfish: *.fishfortran: *.F, *.F77, *.F90, *.F95, *.f, *.f77, *.f90, *.f95, *.pfofsharp: *.fs, *.fsi, *.fsxgn: *.gn, *.gnigo: *.gogroovy: *.gradle, *.groovygzip: *.gzh: *.h, *.hpphaskell: *.c2hs, *.cpphs, *.hs, *.hsc, *.lhshbs: *.hbshs: *.hs, *.lhshtml: *.ejs, *.htm, *.htmlidris: *.idr, *.lidrjava: *.java, *.jspjinja: *.j2, *.jinja, *.jinja2jl: *.jljs: *.js, *.jsx, *.vuejson: *.json, composer.lockjsonl: *.jsonljulia: *.jljupyter: *.ipynb, *.jpynbkotlin: *.kt, *.ktsless: *.lesslicense: *[.-]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, *.scmlog: *.loglua: *.lualz4: *.lz4lzma: *.lzmam4: *.ac, *.m4make: *.mak, *.mk, GNUmakefile, Gnumakefile, Makefile, gnumakefile, makefileman: *.[0-9][cEFMmpSx], *.[0-9lnpx]markdown: *.markdown, *.md, *.mdown, *.mkdnmatlab: *.mmd: *.markdown, *.md, *.mdown, *.mkdnmk: mkfileml: *.mlmsbuild: *.csproj, *.fsproj, *.proj, *.props, *.targets, *.vcxprojnim: *.nimnix: *.nixobjc: *.h, *.mobjcpp: *.h, *.mmocaml: *.ml, *.mli, *.mll, *.mlyorg: *.orgpdf: *.pdfperl: *.PL, *.perl, *.pl, *.plh, *.plx, *.pm, *.tphp: *.php, *.php3, *.php4, *.php5, *.phtmlpod: *.podprotobuf: *.protops: *.cdxml, *.ps1, *.ps1xml, *.psd1, *.psm1puppet: *.erb, *.pp, *.rbpurs: *.purspy: *.pyqmake: *.prf, *.pri, *.pror: *.R, *.Rmd, *.Rnw, *.rrdoc: *.rdocreadme: *README, README*rst: *.rstruby: *.gemspec, *.rb, .irbrc, Gemfile, Rakefilerust: *.rssass: *.sass, *.scssscala: *.sbt, *.scalash: *.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, zshrcsmarty: *.tplsml: *.sig, *.smlsoy: *.soyspark: *.sparksql: *.psql, *.sqlstylus: *.stylsv: *.h, *.sv, *.svh, *.v, *.vgsvg: *.svgswift: *.swiftswig: *.def, *.isystemd: *.automount, *.conf, *.device, *.link, *.mount, *.path, *.scope, *.service, *.slice, *.socket, *.swap, *.target, *.timertaskpaper: *.taskpapertcl: *.tcltex: *.bib, *.cls, *.ltx, *.sty, *.textextile: *.textiletf: *.tftoml: *.toml, Cargo.lockts: *.ts, *.tsxtwig: *.twigtxt: *.txtvala: *.valavb: *.vbverilog: *.sv, *.svh, *.v, *.vhvhdl: *.vhd, *.vhdlvim: *.vimvimscript: *.vimwebidl: *.idl, *.webidl, *.widlwiki: *.mediawiki, *.wikixml: *.xml, *.xml.distxz: *.xzyacc: *.yyaml: *.yaml, *.ymlzsh: *.zsh, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, zlogin, zlogout, zprofile, zshenv, zshrc总结ripgrep的搜索速度真是快的飞起来在浏览代码时对我的帮助非常大。我相信它对于每一个码农的价值都是无限大的特别是结合FZF之后。唯一的弱点是对正则的支持但这是一个取舍如果采用如PCRE那样的库的话一定会极大影响速度。以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持脚本之家。