Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

How to Search Files with ripgrep: Common Commands and Examples

Use ripgrep to search a directory recursively, then refine matches with case, glob, type, and output options. Learn why files may be skipped and how to widen a search safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

From the directory you want to search, run rg 'pattern'. ripgrep searches recursively by default, returning matching lines and their file paths. To limit the search to a directory, add it: rg 'pattern' src/.

ripgrep is a line-oriented tool that recursively searches the current directory for a regular-expression pattern, as the project README explains. The commands below show how to adjust the pattern, file scope, and output when the default search is not quite right.

As an Amazon Associate I earn from qualifying purchases.

Start with a recursive search

Run a search from the directory that contains the files you want to inspect. For example, this searches the current directory and its eligible subdirectories for lines containing TODO:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

rg 'TODO'

Pass a path to search only that location: rg 'TODO' src/. The pattern is a regular expression by default, so ordinary text works directly, while characters such as . have regex meaning.

Choose how the pattern matches

Use the option that matches the kind of text you are looking for:

Goal Command What it does
Ignore letter case rg -i 'todo' Matches upper- and lowercase variants.
Use smart case rg -S 'Todo' Ignores case unless the pattern contains an uppercase letter.
Match the text literally rg -F 'a.b' Treats the pattern as a fixed string, so the period is not a regex wildcard.
Match a whole word rg -w 'main' Restricts the match to the word rather than a longer string containing it.
Match across line breaks rg -U 'firsts+second' Enables multiline matching so the pattern can span lines.

The default regex engine does not support lookaround or backreferences. If a pattern requires either feature, consult the official FAQ and the linked regex documentation; ripgrep also has optional PCRE2 support for patterns that need a different feature set.

Limit which files ripgrep searches

A path, glob, or file type can narrow a search. Use a glob for a one-off filename rule and a type when you want a built-in group of file extensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Scope Command Example use
Named directory rg 'TODO' src/ Search only under src/.
Include a glob rg 'fn run' -g '*.rs' Search paths matching the Rust-file glob.
Exclude a glob rg 'TODO' -g '!*.min.js' Leave minified JavaScript files out.
Include a built-in type rg -t rust 'TODO' Search files in ripgrep’s Rust type.
Exclude a built-in type rg -T js 'TODO' Skip files in ripgrep’s JavaScript type.
List a built-in type’s file globs rg --type-list See the types available in the installed version.

You can define a type for one command with --type-add. For example, rg --type-add 'web:*.{html,css,js}' -tweb title searches files matching those extensions for title. A command-line type addition is not saved automatically.

Understand why a result may be missing

By default, ripgrep respects ignore rules from .gitignore, .ignore, and .rgignore, as well as applicable Git configuration. Its documented precedence is .rgignore over .ignore, and .ignore over Git ignore rules. It also skips hidden files and directories, binary files, and symbolic links unless you change those defaults. The official guide describes these filters and their options.

Widen the search selectively when you know a filter is responsible:

  • rg --hidden 'pattern' includes hidden paths.
  • rg --no-ignore 'pattern' disables ignore-file filtering.
  • rg --text 'pattern' treats binary files as text; control characters may make terminal output difficult to read.
  • rg --follow 'pattern' follows symbolic links.
  • rg -uuu 'pattern' disables ignore, hidden-file, and binary filtering.

The -u option can be repeated for progressively less filtering. If the search scope still seems unexpected, try rg --debug 'pattern' to inspect filtering and configuration behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Change what the output shows

By default, ripgrep prints matching lines with their file paths. These options make results easier to scan or process:

  • rg -C 2 'panic' prints two lines of context before and after each match.
  • rg -l 'TODO' lists matching file names rather than matching lines.
  • rg -c 'TODO' reports the number of matching lines in each file.
  • rg --files lists files ripgrep would search without searching their contents.

The --replace option substitutes matched text in ripgrep’s displayed output; it does not edit files. The FAQ explains that ripgrep alone cannot search and replace files. If you combine match output with another editing tool to change files, review the intended targets before applying potentially destructive edits.

Quickly choose the right command

  • For an ordinary recursive search, start with rg 'pattern'.
  • For literal text, use -F; for case adjustments, use -i or -S.
  • For a smaller file scope, add a path, -g glob, or -t type.
  • If expected files are missing, check ignore rules, hidden paths, binary detection, and symbolic links before broadening the search.
  • Use rg --help as the local reference: available options and support can vary by installed version.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.