Skip to main content

Glob Patterns (-g)

While -t filters by file type (language), -g (--glob) lets you filter by arbitrary path patterns using shell glob syntax.

Including Files

# Only files named exactly "config.yml"
rg "api_url" -g "config.yml"

# Only .conf files anywhere in the tree
rg "listen" -g "*.conf"

# Files in a specific subdirectory
rg "connection" -g "config/*"

Excluding Files (Negation with !)

Prefix the glob with ! to exclude paths:

# Search everything except test files
rg "database_url" -g '!*test*' -g '!*spec*'

# Exclude minified files
rg "function" -g '!*.min.js'

# Exclude multiple directories
rg "password" -g '!vendor/**' -g '!node_modules/**'
Shell Quoting

Wrap globs containing * or ! in single quotes (') to prevent your shell from expanding them before rg receives them.

Combining Type and Glob

# TypeScript files, but not in the __tests__ directory
rg "useState" -t ts -g '!**/__tests__/**'

# YAML config files but not in CI directories
rg "docker_image" -t yaml -g '!.github/**' -g '!.gitlab/**'

Global Globs (.rgignore)

To make an exclusion permanent for all your searches, add it to .rgignore in your home directory:

# ~/.rgignore
!*.lock
!coverage/
!*.snap

Case-Insensitive Globs

rg glob matching is case-insensitive on Windows and case-sensitive on Linux/macOS. If you need portable globs, be explicit:

# Match both README.md and readme.md on case-sensitive filesystems
rg "documentation" -g "README.md" -g "readme.md"