For most recursive searches in a source-code repository, start with ripgrep (rg): it searches recursively by default and respects common ignore rules. Use GNU grep for files and streams, established scripts, and familiar pipelines; keep The Silver Searcher (ag) when an existing workflow depends on it. Before comparing speed or trusting a no-match result, check which files each command searched.
At a glance: choose by workflow
| Tool | Good fit | What to check |
|---|---|---|
GNU grep |
Single files, streams and shell pipelines; scripts or systems where it is already available. | Recursion is explicit: use -r or -R. Their symlink behavior differs. |
ripgrep (rg) |
Recursive searches through source trees, especially when you want repository ignore rules applied by default. | It skips hidden paths and detected binary files by default, as well as ignored paths. Broaden the search if those files matter. |
The Silver Searcher (ag) |
Existing editor integrations, scripts or team conventions that already use it. | It applies ignore-file behavior too; check its configuration and the paths it searches. |
Why search scope matters more than speed
These commands may not search the same files when given what looks like the same task. GNU grep searches recursively only when asked. Ripgrep recurses by default but filters ignored, hidden and detected binary paths. Ag also has ignore-file behavior. As a result, a faster search—or a search that returns no matches—does not necessarily tell you whether a pattern exists in every file you had in mind.
As an Amazon Associate I earn from qualifying purchases.
GNU grep: recursion and symlinks
Use grep -r 'PATTERN' DIR to recurse. According to the GNU Grep 3.12 manual, -r skips symlinks encountered during recursion but follows symlinks supplied on the command line; -R follows all symlinks. GNU grep also offers --include, --exclude and --exclude-dir to narrow recursive searches.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →ripgrep: repository-friendly defaults
Running rg 'PATTERN' searches recursively from the current directory. The ripgrep guide says it respects .gitignore, .ignore and .rgignore, and skips hidden paths and detected binary files by default.
#1 Best Overall
- Include hidden paths with
rg --hidden 'PATTERN'; the guide also showsrg -. 'PATTERN'. - Disregard ignore files with
rg --no-ignore 'PATTERN'. - Disable all automatic filtering with
rg -uu 'PATTERN'. This can expand the search substantially.
ag: useful when a workflow already expects it
The Debian trixie manpage for silversearcher-ag 2.2.0+git20200805-1.2 describes ignore handling for .gitignore, .hgignore and .ignore files. Check the ag manpage for its options and configuration. If an editor plugin or team script calls ag, keeping it can be simpler than changing a working integration.
How to investigate a missing match
- Confirm the search root. Check your current directory with
pwd, or supply the directory explicitly, so you know which tree the command examined. - Check filtering. With
rg, ignored, hidden and detected binary paths are common reasons a file is omitted. Tryrg --hidden --no-ignore 'PATTERN' DIRto include hidden paths and disregard ignore files, orrg -uu 'PATTERN' DIRto disable all automatic filtering. - Check recursion and links. GNU grep needs
-ror-Rfor recursive search. If symlinks matter, choose between their documented behaviors deliberately. - Inspect the file itself and its encoding. Binary detection or unusual input can affect whether a text search displays a result. Avoid forcing binary data to the terminal without understanding the consequences.
A broader search can be slower and produce noisy results, so use it to diagnose scope rather than assuming it should be the default for every query.
Compare speed fairly
The ripgrep project’s FAQ says rg is typically 5–100 times faster than GNU grep on large codebases, depending on the pattern and corpus. That is the project’s own characterization, not an independent benchmark or a guarantee for your files or machine. The ripgrep README reports one Linux kernel source-tree example in which ripgrep took 0.082 seconds and ag took 0.443 seconds for the shown commands. Those timings describe that example, not an expected speedup for other searches.
For a useful local comparison, run the same pattern against the same files, with the same ignore and hidden-file rules and comparable output. A search that skips more paths can finish sooner without matching the other tool’s scope. The project describes ripgrep’s parallel traversal, literal-matching optimizations and memory-mapped I/O as design features; actual performance still depends on the workload.
Workflow details that can decide it
- Portability and availability: GNU grep is a familiar choice for scripts and pipelines, particularly where it is already installed. Ripgrep’s project documentation lists first-class Windows, macOS and Linux support; check what is available on the target system.
- Output and compressed files: The ripgrep project documents JSON output and compressed-file searching with
-z. Verify the behavior against your installed version when a script depends on it. - Binary input: GNU’s manual warns that
grep -atreats binary input as text and may send binary garbage to the terminal, with potentially harmful effects. Use it cautiously, especially in an interactive terminal. - Ag comparisons: The ripgrep project’s comparison page says both ag and ripgrep skip ignored, hidden and binary files by default, and favors ripgrep on speed and several features. Treat that as the project’s own comparison, not a neutral third-party audit.
A practical decision
- Choose
rgfor ordinary recursive repository searches, then broaden its filters when hidden, ignored or binary paths are in scope. - Choose GNU
grepfor a stream, a known set of files, or a script whose environment and behavior already rely on grep. - Choose
agwhen an existing integration depends on it and there is no practical reason to change. - When speed is the deciding factor, compare the commands on your own corpus with equivalent scope and output.
These tools overlap, but their defaults and integrations are not identical; this is a workflow-based choice, not a claim that one command replaces every use of the others.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




