rg — Filters

Type and Glob Filtering

Type filter (--type) — search only specific file types
rg --type adoc 'include::' ~/atelier/_bibliotheca/domus-captures/docs/

--type (short: -t) restricts search to known file types. rg knows 100+ types out of the box. adoc matches .adoc, .asc, *.asciidoc.


Type list — see all built-in type definitions
rg --type-list | head -20

Expected output (partial):

agda: *.agda, *.lagda
aidl: *.aidl
amake: *.bp, *.mk
asciidoc: *.adoc, *.asc, *.asciidoc
asm: *.S, *.asm, *.s

Pipe to rg itself to find a specific type: rg --type-list | rg yaml.


Glob include (--glob) — match by file pattern
rg --glob '*.adoc' 'xref:' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages/

--glob (short: -g) uses gitignore-style glob syntax. Unlike --type, globs give you arbitrary pattern control.


Glob exclude — prefix with ! to negate
rg --glob '!*.log' 'error' /var/log/

Negated globs exclude matching files. Here: search all files in /var/log/ except .log files (useful when logs come in multiple formats).


Multiple globs — combine include and exclude
rg -g '*.adoc' -g '!*gotchas*' 'include::partial' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages/codex/

Multiple -g flags are ANDed for excludes, ORed for includes. Here: search .adoc files but skip anything with gotchas in the name.


Hidden files (--hidden) — include dotfiles
rg --hidden 'alias' ~/atelier/_bibliotheca/domus-captures/

By default rg skips hidden files and directories (those starting with .). --hidden includes them. Useful for searching .gitignore, .claude/, .github/.


No ignore (--no-ignore) — override .gitignore rules
rg --no-ignore 'node_modules' ~/atelier/_bibliotheca/domus-captures/

rg respects .gitignore, .rgignore, and .ignore by default. --no-ignore disables all ignore rules. Combine with --hidden for truly exhaustive search: rg --no-ignore --hidden.


Max depth (--max-depth) — limit recursion
rg --max-depth 2 'nav_order' ~/atelier/_bibliotheca/domus-captures/docs/

Restricts search to N levels of directories. --max-depth 1 = current directory only (no recursion). --max-depth 2 = one level of subdirectories.


Follow symlinks (--follow)
rg --follow 'pattern' /etc/

By default rg does NOT follow symlinks. --follow (short: -L) enables it. Important for /etc/ where many files are symlinks to alternatives or other config managers.


Custom type definition (--type-add) — define your own types
rg --type-add 'antora:antora.yml' --type antora 'version' ~/atelier/_bibliotheca/domus-captures/docs/

--type-add defines a new type for this invocation. Format: name:glob. Multiple globs: name:*.a,*.b. Permanent definitions go in ~/.config/ripgrep/config (one flag per line).