Skip to main content

File Type Filters

rg includes a built-in database of file type mappings. This lets you restrict your search to a specific language without writing glob patterns.

Listing Available Types

rg --type-list

This prints all built-in types:

py: *.py
js: *.js, *.mjs, *.cjs
ts: *.ts, *.tsx
go: *.go
rust: *.rs
...

Including a Type (-t)

# Only Python files
rg "def process" -t py

# Only TypeScript files
rg "interface User" -t ts

# Only config files (yaml + toml + json)
rg "database" -t yaml -t toml -t json

Excluding a Type (-T)

-T is the inverse — exclude all files of that type:

# Search everything EXCEPT test files
rg "api_key" -T test

# Search everything EXCEPT minified JS
rg "function" -T min

Defining Custom Types (--type-add)

If rg --type-list doesn't include your file type, define it inline:

# Treat .env files as a type called "env"
rg --type-add "env:*.env,*.env.*" -t env "SECRET"

To make this permanent, add it to your ~/.config/ripgrep/ripgreprc:

--type-add=env:*.env,*.env.*,*.env.local

Common Type Combinations

# Scan a full-stack project: JS + TS + Python + YAML
rg "localhost:8080" -t js -t ts -t py -t yaml

# Only infrastructure files
rg "region" -t terraform -t yaml -t json

# Only documentation
rg "deprecated" -t md -t rst