Control which files ripgrep searches

Scope ripgrep searches by glob, reveal hidden files, and inspect the file list before searching.

how-to4 steps

Updated

in short

Inspect the search scope with --files, then use a quoted glob and fixed-string matching to find a literal token.

Work through these disposable fixtures before adapting the commands to your own files. Run the steps in the same terminal session.

Tools used

Before you start

  • Bash on Linux or macOS
  • The listed tools installed and available on PATH

Steps

  1. Step 1: Create a small source tree

    The ignored directory and hidden file make the scope visible.

    sh
    trmn_guide_dir="$(mktemp -d)"
    cd "$trmn_guide_dir"
    mkdir -p src vendor
    printf 'vendor/\n' > .ignore
    printf 'TODO ship endpoint\n' > src/app.py
    printf 'TODO draft docs\n' > notes.md
    printf 'TODO upstream fix\n' > vendor/library.py
    printf 'TODO rotate fixture\n' > .settings
  2. Step 2: Inspect the default file set

    Hidden files and paths matched by .ignore are omitted. Sorting keeps this example stable.

    sh
    rg --no-config --files | sort
    output
    notes.md
    src/app.py
  3. Step 3: Search just the Python files

    Quote the glob so the shell leaves it for ripgrep. -F treats the token literally.

    sh
    rg --no-config --color never -n -F -g '*.py' TODO .
    output
    ./src/app.py:1:TODO ship endpoint
  4. Step 4: Include hidden files while preserving ignores

    --hidden includes .settings; it does not disable .ignore. --no-ignore is a separate choice.

    sh
    rg --no-config --color never --hidden -n -F TODO . | sort
    output
    ./.settings:1:TODO rotate fixture
    ./notes.md:1:TODO draft docs
    ./src/app.py:1:TODO ship endpoint

Further reading

[ripgrep guide](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md) [ripgrep FAQ](https://github.com/BurntSushi/ripgrep/blob/master/FAQ.md)

FAQ

Why use --no-config?
It prevents a personal ripgrep configuration from changing the fixture results.
Why does a search return exit code 1?
For ripgrep, 1 means no match. Exit code 2 indicates an error. Account for this distinction when scripting.

related