• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.cargo/H12-Jun-2021-98

.github/H12-Jun-2021-483424

HomebrewFormula/H12-Jun-2021-

benchsuite/H12-Jun-2021-8,4797,897

cargo-crates/H03-May-2022-1,270,7911,048,526

ci/H12-Jun-2021-375244

complete/H12-Jun-2021-641560

crates/H12-Jun-2021-37,91626,558

doc/H12-Jun-2021-308218

pkg/brew/H12-Jun-2021-2419

scripts/H12-Jun-2021-3427

tests/H12-Jun-2021-4,4543,229

.gitignoreH A D12-Jun-2021259 2219

CHANGELOG.mdH A D12-Jun-202169.3 KiB1,4781,251

COPYINGH A D12-Jun-2021126 42

Cargo.lockH A D12-Jun-202113.8 KiB609542

Cargo.tomlH A D12-Jun-20213 KiB10895

Cross.tomlH A D12-Jun-2021361 128

FAQ.mdH A D12-Jun-202140.9 KiB1,025798

GUIDE.mdH A D12-Jun-202139.2 KiB1,013813

LICENSE-MITH A D12-Jun-20211.1 KiB2217

README.mdH A D12-Jun-202116.9 KiB437328

RELEASE-CHECKLIST.mdH A D12-Jun-20212.5 KiB5250

UNLICENSEH A D12-Jun-20211.2 KiB2520

build.rsH A D03-May-20227.8 KiB240192

rustfmt.tomlH A D12-Jun-202144 32

README.md

1ripgrep (rg)
2------------
3ripgrep is a line-oriented search tool that recursively searches the current
4directory for a regex pattern. By default, ripgrep will respect gitignore rules
5and automatically skip hidden files/directories and binary files. ripgrep
6has first class support on Windows, macOS and Linux, with binary downloads
7available for [every release](https://github.com/BurntSushi/ripgrep/releases).
8ripgrep is similar to other popular search tools like The Silver Searcher, ack
9and grep.
10
11[![Build status](https://github.com/BurntSushi/ripgrep/workflows/ci/badge.svg)](https://github.com/BurntSushi/ripgrep/actions)
12[![Crates.io](https://img.shields.io/crates/v/ripgrep.svg)](https://crates.io/crates/ripgrep)
13[![Packaging status](https://repology.org/badge/tiny-repos/ripgrep.svg)](https://repology.org/project/ripgrep/badges)
14
15Dual-licensed under MIT or the [UNLICENSE](https://unlicense.org).
16
17
18### CHANGELOG
19
20Please see the [CHANGELOG](CHANGELOG.md) for a release history.
21
22### Documentation quick links
23
24* [Installation](#installation)
25* [User Guide](GUIDE.md)
26* [Frequently Asked Questions](FAQ.md)
27* [Regex syntax](https://docs.rs/regex/1/regex/#syntax)
28* [Configuration files](GUIDE.md#configuration-file)
29* [Shell completions](FAQ.md#complete)
30* [Building](#building)
31* [Translations](#translations)
32
33
34### Screenshot of search results
35
36[![A screenshot of a sample search with ripgrep](https://burntsushi.net/stuff/ripgrep1.png)](https://burntsushi.net/stuff/ripgrep1.png)
37
38
39### Quick examples comparing tools
40
41This example searches the entire
42[Linux kernel source tree](https://github.com/BurntSushi/linux)
43(after running `make defconfig && make -j8`) for `[A-Z]+_SUSPEND`, where
44all matches must be words. Timings were collected on a system with an Intel
45i7-6900K 3.2 GHz.
46
47Please remember that a single benchmark is never enough! See my
48[blog post on ripgrep](https://blog.burntsushi.net/ripgrep/)
49for a very detailed comparison with more benchmarks and analysis.
50
51| Tool | Command | Line count | Time |
52| ---- | ------- | ---------- | ---- |
53| ripgrep (Unicode) | `rg -n -w '[A-Z]+_SUSPEND'` | 452 | **0.136s** |
54| [git grep](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `git grep -P -n -w '[A-Z]+_SUSPEND'` | 452 | 0.348s |
55| [ugrep (Unicode)](https://github.com/Genivia/ugrep) | `ugrep -r --ignore-files --no-hidden -I -w '[A-Z]+_SUSPEND'` | 452 | 0.506s |
56| [The Silver Searcher](https://github.com/ggreer/the_silver_searcher) | `ag -w '[A-Z]+_SUSPEND'` | 452 | 0.654s |
57| [git grep](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND'` | 452 | 1.150s |
58| [ack](https://github.com/beyondgrep/ack3) | `ack -w '[A-Z]+_SUSPEND'` | 452 | 4.054s |
59| [git grep (Unicode)](https://www.kernel.org/pub/software/scm/git/docs/git-grep.html) | `LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND'` | 452 | 4.205s |
60
61Here's another benchmark on the same corpus as above that disregards gitignore
62files and searches with a whitelist instead. The corpus is the same as in the
63previous benchmark, and the flags passed to each command ensure that they are
64doing equivalent work:
65
66| Tool | Command | Line count | Time |
67| ---- | ------- | ---------- | ---- |
68| ripgrep | `rg -uuu -tc -n -w '[A-Z]+_SUSPEND'` | 388 | **0.096s** |
69| [ugrep](https://github.com/Genivia/ugrep) | `ugrep -r -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND'` | 388 | 0.493s |
70| [GNU grep](https://www.gnu.org/software/grep/) | `egrep -r -n --include='*.c' --include='*.h' -w '[A-Z]+_SUSPEND'` | 388 | 0.806s |
71
72And finally, a straight-up comparison between ripgrep, ugrep and GNU grep on a
73single large file cached in memory
74(~13GB, [`OpenSubtitles.raw.en.gz`](http://opus.nlpl.eu/download.php?f=OpenSubtitles/v2018/mono/OpenSubtitles.raw.en.gz)):
75
76| Tool | Command | Line count | Time |
77| ---- | ------- | ---------- | ---- |
78| ripgrep | `rg -w 'Sherlock [A-Z]\w+'` | 7882 | **2.769s** |
79| [ugrep](https://github.com/Genivia/ugrep) | `ugrep -w 'Sherlock [A-Z]\w+'` | 7882 | 6.802s |
80| [GNU grep](https://www.gnu.org/software/grep/) | `LC_ALL=en_US.UTF-8 egrep -w 'Sherlock [A-Z]\w+'` | 7882 | 9.027s |
81
82In the above benchmark, passing the `-n` flag (for showing line numbers)
83increases the times to `3.423s` for ripgrep and `13.031s` for GNU grep. ugrep
84times are unaffected by the presence or absence of `-n`.
85
86
87### Why should I use ripgrep?
88
89* It can replace many use cases served by other search tools
90  because it contains most of their features and is generally faster. (See
91  [the FAQ](FAQ.md#posix4ever) for more details on whether ripgrep can truly
92  replace grep.)
93* Like other tools specialized to code search, ripgrep defaults to recursive
94  directory search and won't search files ignored by your
95  `.gitignore`/`.ignore`/`.rgignore` files. It also ignores hidden and binary
96  files by default. ripgrep also implements full support for `.gitignore`,
97  whereas there are many bugs related to that functionality in other code
98  search tools claiming to provide the same functionality.
99* ripgrep can search specific types of files. For example, `rg -tpy foo`
100  limits your search to Python files and `rg -Tjs foo` excludes JavaScript
101  files from your search. ripgrep can be taught about new file types with
102  custom matching rules.
103* ripgrep supports many features found in `grep`, such as showing the context
104  of search results, searching multiple patterns, highlighting matches with
105  color and full Unicode support. Unlike GNU grep, ripgrep stays fast while
106  supporting Unicode (which is always on).
107* ripgrep has optional support for switching its regex engine to use PCRE2.
108  Among other things, this makes it possible to use look-around and
109  backreferences in your patterns, which are not supported in ripgrep's default
110  regex engine. PCRE2 support can be enabled with `-P/--pcre2` (use PCRE2
111  always) or `--auto-hybrid-regex` (use PCRE2 only if needed). An alternative
112  syntax is provided via the `--engine (default|pcre2|auto-hybrid)` option.
113* ripgrep supports searching files in text encodings other than UTF-8, such
114  as UTF-16, latin-1, GBK, EUC-JP, Shift_JIS and more. (Some support for
115  automatically detecting UTF-16 is provided. Other text encodings must be
116  specifically specified with the `-E/--encoding` flag.)
117* ripgrep supports searching files compressed in a common format (brotli,
118  bzip2, gzip, lz4, lzma, xz, or zstandard) with the `-z/--search-zip` flag.
119* ripgrep supports
120  [arbitrary input preprocessing filters](GUIDE.md#preprocessor)
121  which could be PDF text extraction, less supported decompression, decrypting,
122  automatic encoding detection and so on.
123
124In other words, use ripgrep if you like speed, filtering by default, fewer
125bugs and Unicode support.
126
127
128### Why shouldn't I use ripgrep?
129
130Despite initially not wanting to add every feature under the sun to ripgrep,
131over time, ripgrep has grown support for most features found in other file
132searching tools. This includes searching for results spanning across multiple
133lines, and opt-in support for PCRE2, which provides look-around and
134backreference support.
135
136At this point, the primary reasons not to use ripgrep probably consist of one
137or more of the following:
138
139* You need a portable and ubiquitous tool. While ripgrep works on Windows,
140  macOS and Linux, it is not ubiquitous and it does not conform to any
141  standard such as POSIX. The best tool for this job is good old grep.
142* There still exists some other feature (or bug) not listed in this README that
143  you rely on that's in another tool that isn't in ripgrep.
144* There is a performance edge case where ripgrep doesn't do well where another
145  tool does do well. (Please file a bug report!)
146* ripgrep isn't possible to install on your machine or isn't available for your
147  platform. (Please file a bug report!)
148
149
150### Is it really faster than everything else?
151
152Generally, yes. A large number of benchmarks with detailed analysis for each is
153[available on my blog](https://blog.burntsushi.net/ripgrep/).
154
155Summarizing, ripgrep is fast because:
156
157* It is built on top of
158  [Rust's regex engine](https://github.com/rust-lang/regex).
159  Rust's regex engine uses finite automata, SIMD and aggressive literal
160  optimizations to make searching very fast. (PCRE2 support can be opted into
161  with the `-P/--pcre2` flag.)
162* Rust's regex library maintains performance with full Unicode support by
163  building UTF-8 decoding directly into its deterministic finite automaton
164  engine.
165* It supports searching with either memory maps or by searching incrementally
166  with an intermediate buffer. The former is better for single files and the
167  latter is better for large directories. ripgrep chooses the best searching
168  strategy for you automatically.
169* Applies your ignore patterns in `.gitignore` files using a
170  [`RegexSet`](https://docs.rs/regex/1/regex/struct.RegexSet.html).
171  That means a single file path can be matched against multiple glob patterns
172  simultaneously.
173* It uses a lock-free parallel recursive directory iterator, courtesy of
174  [`crossbeam`](https://docs.rs/crossbeam) and
175  [`ignore`](https://docs.rs/ignore).
176
177
178### Feature comparison
179
180Andy Lester, author of [ack](https://beyondgrep.com/), has published an
181excellent table comparing the features of ack, ag, git-grep, GNU grep and
182ripgrep: https://beyondgrep.com/feature-comparison/
183
184Note that ripgrep has grown a few significant new features recently that
185are not yet present in Andy's table. This includes, but is not limited to,
186configuration files, passthru, support for searching compressed files,
187multiline search and opt-in fancy regex support via PCRE2.
188
189
190### Installation
191
192The binary name for ripgrep is `rg`.
193
194**[Archives of precompiled binaries for ripgrep are available for Windows,
195macOS and Linux.](https://github.com/BurntSushi/ripgrep/releases)** Linux and
196Windows binaries are static executables. Users of platforms not explicitly
197mentioned below are advised to download one of these archives.
198
199If you're a **macOS Homebrew** or a **Linuxbrew** user, then you can install
200ripgrep from homebrew-core:
201
202```
203$ brew install ripgrep
204```
205
206If you're a **MacPorts** user, then you can install ripgrep from the
207[official ports](https://www.macports.org/ports.php?by=name&substr=ripgrep):
208
209```
210$ sudo port install ripgrep
211```
212
213If you're a **Windows Chocolatey** user, then you can install ripgrep from the
214[official repo](https://chocolatey.org/packages/ripgrep):
215
216```
217$ choco install ripgrep
218```
219
220If you're a **Windows Scoop** user, then you can install ripgrep from the
221[official bucket](https://github.com/ScoopInstaller/Main/blob/master/bucket/ripgrep.json):
222
223```
224$ scoop install ripgrep
225```
226
227If you're an **Arch Linux** user, then you can install ripgrep from the official repos:
228
229```
230$ pacman -S ripgrep
231```
232
233If you're a **Gentoo** user, you can install ripgrep from the
234[official repo](https://packages.gentoo.org/packages/sys-apps/ripgrep):
235
236```
237$ emerge sys-apps/ripgrep
238```
239
240If you're a **Fedora** user, you can install ripgrep from official
241repositories.
242
243```
244$ sudo dnf install ripgrep
245```
246
247If you're an **openSUSE** user, ripgrep is included in **openSUSE Tumbleweed**
248and **openSUSE Leap** since 15.1.
249
250```
251$ sudo zypper install ripgrep
252```
253
254If you're a **RHEL/CentOS 7/8** user, you can install ripgrep from
255[copr](https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/):
256
257```
258$ sudo yum-config-manager --add-repo=https://copr.fedorainfracloud.org/coprs/carlwgeorge/ripgrep/repo/epel-7/carlwgeorge-ripgrep-epel-7.repo
259$ sudo yum install ripgrep
260```
261
262If you're a **Nix** user, you can install ripgrep from
263[nixpkgs](https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/text/ripgrep/default.nix):
264
265```
266$ nix-env --install ripgrep
267$ # (Or using the attribute name, which is also ripgrep.)
268```
269
270If you're a **Debian** user (or a user of a Debian derivative like **Ubuntu**),
271then ripgrep can be installed using a binary `.deb` file provided in each
272[ripgrep release](https://github.com/BurntSushi/ripgrep/releases).
273
274```
275$ curl -LO https://github.com/BurntSushi/ripgrep/releases/download/12.1.1/ripgrep_12.1.1_amd64.deb
276$ sudo dpkg -i ripgrep_12.1.1_amd64.deb
277```
278
279If you run Debian Buster (currently Debian stable) or Debian sid, ripgrep is
280[officially maintained by Debian](https://tracker.debian.org/pkg/rust-ripgrep).
281```
282$ sudo apt-get install ripgrep
283```
284
285If you're an **Ubuntu Cosmic (18.10)** (or newer) user, ripgrep is
286[available](https://launchpad.net/ubuntu/+source/rust-ripgrep) using the same
287packaging as Debian:
288
289```
290$ sudo apt-get install ripgrep
291```
292
293(N.B. Various snaps for ripgrep on Ubuntu are also available, but none of them
294seem to work right and generate a number of very strange bug reports that I
295don't know how to fix and don't have the time to fix. Therefore, it is no
296longer a recommended installation option.)
297
298If you're a **FreeBSD** user, then you can install ripgrep from the
299[official ports](https://www.freshports.org/textproc/ripgrep/):
300
301```
302# pkg install ripgrep
303```
304
305If you're an **OpenBSD** user, then you can install ripgrep from the
306[official ports](https://openports.se/textproc/ripgrep):
307
308```
309$ doas pkg_add ripgrep
310```
311
312If you're a **NetBSD** user, then you can install ripgrep from
313[pkgsrc](https://pkgsrc.se/textproc/ripgrep):
314
315```
316# pkgin install ripgrep
317```
318
319If you're a **Haiku x86_64** user, then you can install ripgrep from the
320[official ports](https://github.com/haikuports/haikuports/tree/master/sys-apps/ripgrep):
321
322```
323$ pkgman install ripgrep
324```
325
326If you're a **Haiku x86_gcc2** user, then you can install ripgrep from the
327same port as Haiku x86_64 using the x86 secondary architecture build:
328
329```
330$ pkgman install ripgrep_x86
331```
332
333If you're a **Rust programmer**, ripgrep can be installed with `cargo`.
334
335* Note that the minimum supported version of Rust for ripgrep is **1.34.0**,
336  although ripgrep may work with older versions.
337* Note that the binary may be bigger than expected because it contains debug
338  symbols. This is intentional. To remove debug symbols and therefore reduce
339  the file size, run `strip` on the binary.
340
341```
342$ cargo install ripgrep
343```
344
345
346### Building
347
348ripgrep is written in Rust, so you'll need to grab a
349[Rust installation](https://www.rust-lang.org/) in order to compile it.
350ripgrep compiles with Rust 1.34.0 (stable) or newer. In general, ripgrep tracks
351the latest stable release of the Rust compiler.
352
353To build ripgrep:
354
355```
356$ git clone https://github.com/BurntSushi/ripgrep
357$ cd ripgrep
358$ cargo build --release
359$ ./target/release/rg --version
3600.1.3
361```
362
363If you have a Rust nightly compiler and a recent Intel CPU, then you can enable
364additional optional SIMD acceleration like so:
365
366```
367RUSTFLAGS="-C target-cpu=native" cargo build --release --features 'simd-accel'
368```
369
370The `simd-accel` feature enables SIMD support in certain ripgrep dependencies
371(responsible for transcoding). They are not necessary to get SIMD optimizations
372for search; those are enabled automatically. Hopefully, some day, the
373`simd-accel` feature will similarly become unnecessary. **WARNING:** Currently,
374enabling this option can increase compilation times dramatically.
375
376Finally, optional PCRE2 support can be built with ripgrep by enabling the
377`pcre2` feature:
378
379```
380$ cargo build --release --features 'pcre2'
381```
382
383(Tip: use `--features 'pcre2 simd-accel'` to also include compile time SIMD
384optimizations, which will only work with a nightly compiler.)
385
386Enabling the PCRE2 feature works with a stable Rust compiler and will
387attempt to automatically find and link with your system's PCRE2 library via
388`pkg-config`. If one doesn't exist, then ripgrep will build PCRE2 from source
389using your system's C compiler and then statically link it into the final
390executable. Static linking can be forced even when there is an available PCRE2
391system library by either building ripgrep with the MUSL target or by setting
392`PCRE2_SYS_STATIC=1`.
393
394ripgrep can be built with the MUSL target on Linux by first installing the MUSL
395library on your system (consult your friendly neighborhood package manager).
396Then you just need to add MUSL support to your Rust toolchain and rebuild
397ripgrep, which yields a fully static executable:
398
399```
400$ rustup target add x86_64-unknown-linux-musl
401$ cargo build --release --target x86_64-unknown-linux-musl
402```
403
404Applying the `--features` flag from above works as expected. If you want to
405build a static executable with MUSL and with PCRE2, then you will need to have
406`musl-gcc` installed, which might be in a separate package from the actual
407MUSL library, depending on your Linux distribution.
408
409
410### Running tests
411
412ripgrep is relatively well-tested, including both unit tests and integration
413tests. To run the full test suite, use:
414
415```
416$ cargo test --all
417```
418
419from the repository root.
420
421
422### Vulnerability reporting
423
424For reporting a security vulnerability, please
425[contact Andrew Gallant](https://blog.burntsushi.net/about/),
426which has my email address and PGP public key if you wish to send an encrypted
427message.
428
429
430### Translations
431
432The following is a list of known translations of ripgrep's documentation. These
433are unofficially maintained and may not be up to date.
434
435* [Chinese](https://github.com/chinanf-boy/ripgrep-zh#%E6%9B%B4%E6%96%B0-)
436* [Spanish](https://github.com/UltiRequiem/traducciones/tree/master/ripgrep)
437