File Filtering¶
These flags control which files are searched.
Filtering Decision Flow¶
Ripgrep applies multiple filtering layers to determine which files to search:
flowchart LR
Start[File Discovered] --> Hidden{Hidden
file?}
Hidden -->|Yes + no --hidden| Skip1[Skip]
Hidden -->|No or --hidden| Ignore{In ignore
files?}
Ignore -->|Yes + no -u| Skip2[Skip]
Ignore -->|No or -u| Type{Matches file
type filter?}
Type -->|No -t match| Skip3[Skip]
Type -->|-T exclude| Skip3
Type -->|Yes or no filter| Glob{Matches glob
patterns?}
Glob -->|No match| Skip4[Skip]
Glob -->|-g exclude| Skip4
Glob -->|Yes or no filter| Binary{Binary
file?}
Binary -->|Yes + no --binary/-a| Skip5[Skip]
Binary -->|No or --binary/-a| Size{Exceeds
max size?}
Size -->|Yes| Skip6[Skip]
Size -->|No or no limit| Depth{Beyond
max depth?}
Depth -->|Yes| Skip7[Skip]
Depth -->|No or no limit| Search[Search File]
style Start fill:#e1f5ff
style Search fill:#c8e6c9
style Skip1 fill:#ffcdd2
style Skip2 fill:#ffcdd2
style Skip3 fill:#ffcdd2
style Skip4 fill:#ffcdd2
style Skip5 fill:#ffcdd2
style Skip6 fill:#ffcdd2
style Skip7 fill:#ffcdd2
Figure: File filtering decision flow showing how ripgrep evaluates files through multiple filtering layers.
Quick reference: Common filtering patterns
- Search specific file types:
rg -trust patternorrg -tpy pattern - Search with globs:
rg -g '*.rs' pattern - Search ignored files:
rg -u pattern - Search everything (including hidden/binary):
rg -uuu pattern - Exclude file types:
rg -Tlog pattern - Limit search depth:
rg -d 2 pattern
File Type Filtering¶
-
-t, --type TYPE: Only search files of this type -
-T, --type-not TYPE: Exclude files of this type -
--type-list: Show all supported file types -
--type-add TYPESPEC: Define custom file types# Source: crates/core/flags/defs.rs:6936-6969 # Define a custom type 'web' for web files rg --type-add 'web:*.{html,css,js}' -tweb pattern # (1)! # Define 'config' type for configuration files rg --type-add 'config:*.{yml,yaml,toml,json}' -tconfig 'port' # (2)! # Combine with multiple type definitions rg --type-add 'foo:*.foo' --type-add 'bar:*.bar' -tfoo -tbar pattern # (3)! # Compose types from other types using include: rg --type-add 'src:include:cpp,py,md' -tsrc pattern # (4)! # Combine include: with additional globs rg --type-add 'src:include:cpp,py,md' --type-add 'src:*.foo' -tsrc pattern # (5)! -
Format is
name:glob- creates type 'web', then-twebuses it - Use brace expansion
{yml,yaml,toml,json}for multiple extensions - Chain multiple
--type-addto define several types in one command - Use
include:syntax to compose a type from multiple existing types - Add more globs to an included type definition for further customization
The format is name:glob, where name is your custom type name and glob is a file pattern. Multiple globs can be specified using brace expansion {ext1,ext2}. You can also use name:include:type1,type2,... to compose a new type from existing types.
--type-clear TYPE: Clear existing type definitions for a type This flag clears all glob patterns for the specified type, including built-in definitions. Useful when you want to completely redefine a type without inheriting default patterns.
Type persistence
Custom types defined with --type-add must be passed to every invocation. For persistent type definitions, use your configuration file.
Ripgrep knows about common file extensions for popular languages and formats. You can also define custom types in your configuration file.
Combining filtering mechanisms
You can combine file type filtering, glob patterns, and other flags for precise control:
Glob Patterns¶
-
-g, --glob PATTERN: Include/exclude files matching glob pattern# Only search .rs files rg -g '*.rs' pattern # (1)! # Search .py files in src/ directory tree rg -g 'src/**/*.py' pattern # (2)! # Exclude minified JavaScript rg -g '!*.min.js' pattern # (3)! # Combine multiple globs rg -g '*.{rs,toml}' pattern # (4)! # Match single character with ? rg -g 'test?.rs' pattern # (5)! # Match character classes with [...] rg -g 'file[0-9].txt' pattern # (6)! rg -g 'data[a-z].csv' pattern -
*matches any characters except/(directory separator) **matches across directories - use for recursive patterns!prefix negates the pattern - excludes matching files{rs,toml}expands to multiple extensions in one pattern?matches exactly one character - use for single-char variations[0-9]matches any single digit -[a-z]matches any lowercase letter
Glob syntax:
- * - Match any characters (except /)
- ** - Match any characters including / (directory recursion)
- ? - Match exactly one character
- [...] - Match any character in the brackets (e.g., [0-9], [a-z], [abc])
- ! prefix - Exclude files matching the pattern
-
--iglob PATTERN: Like--globbut case-insensitive -
--glob-case-insensitive: Make all glob patterns case-insensitiveThis is equivalent to using# Make all -g/--glob patterns case-insensitive rg --glob-case-insensitive -g '*.TXT' -g '*.LOG' pattern--iglobfor all glob patterns. Useful when you have multiple globs and want them all case-insensitive without converting each to--iglob.
Preview matched files
Use rg --files -g 'pattern' to preview which files match your glob patterns before searching. This helps verify your glob syntax is correct.
Common glob pattern recipes
Here are common glob pattern use cases:
Unrestricted Search¶
The -u flag progressively removes ripgrep's smart filtering. Each -u adds more:
flowchart LR
Default[Default Search] --> U1[-u flag]
U1 --> U2[-uu flag]
U2 --> U3[-uuu flag]
Default --> D1["✓ Respects .gitignore
✓ Skips hidden files
✓ Skips binary files"]
U1 --> D2["✗ Ignores .gitignore
✓ Skips hidden files
✓ Skips binary files"]
U2 --> D3["✗ Ignores .gitignore
✗ Searches hidden files
✗ Searches binary files"]
U3 --> D4["✗ All filtering disabled
✗ Maximum coverage
✗ Kitchen sink mode"]
style Default fill:#e8f5e9
style U1 fill:#fff3e0
style U2 fill:#ffe0b2
style U3 fill:#ffccbc
Figure: Progressive unrestricted search showing how each -u flag removes filtering layers.
Default behavior
By default, ripgrep respects .gitignore, skips hidden files, and ignores binary files. Use -u flags to override these behaviors.
-
-u: Don't respect.gitignoreand other ignore files -
This combines-uu: Also search hidden files (equivalent to-u --hidden)-u(ignore .gitignore) with--hidden(search hidden files). Binary files may also be searched as a side effect in some contexts. -
This is the most permissive mode, combining all unrestricted behaviors: searches ignored files (-uuu: Disable all filtering (ignore files, hidden files, and binary detection).gitignore), hidden files (.dotfiles), and doesn't skip binary files.
Use -u when you need to search .gitignored files, -uu when you also need hidden/binary files, and -uuu for maximum coverage.
Granular Ignore Control¶
Instead of using -u flags, you can selectively disable specific ignore mechanisms:
graph TD
Default[Default: All Ignore Files Active] --> VCS[--no-ignore-vcs]
Default --> Global[--no-ignore-global]
Default --> Dot[--no-ignore-dot]
Default --> Parent[--no-ignore-parent]
Default --> Exclude[--no-ignore-exclude]
VCS --> V1["Skip .gitignore, .hgignore
Still respect .ignore"]
Global --> G1["Skip global gitignore
~/.gitignore, etc."]
Dot --> D1["Skip .ignore files
Still respect .gitignore"]
Parent --> P1["Skip parent directory
ignore files"]
Exclude --> E1["Skip .git/info/exclude
Still respect .gitignore"]
style Default fill:#e1f5ff
style VCS fill:#fff3e0
style Global fill:#fff3e0
style Dot fill:#fff3e0
style Parent fill:#fff3e0
style Exclude fill:#fff3e0
Figure: Granular ignore control flags - each flag disables a specific ignore mechanism.
-
--no-ignore-vcs: Don't respect version control ignore files (.gitignore, etc.) -
--no-ignore-global: Don't respect global ignore files -
--no-ignore-dot: Don't respect.ignorefiles -
--no-ignore-parent: Don't respect ignore files in parent directories (see Advanced Filtering) -
--no-ignore-exclude: Don't respect.git/info/excludefiles
Combining granular flags
These flags can be combined for precise control over which ignore files are respected. Using -u is equivalent to enabling all of these flags at once.
Hidden Files and Symlinks¶
-
By default, hidden files are skipped.--hidden: Search hidden files and directories (those starting with.) -
-L, --follow: Follow symbolic links
Symlink behavior
By default, symlinks are not followed to avoid cycles and duplication. Use --follow carefully in directories with complex symlink structures.
Directory Depth¶
-d, --max-depth NUM: Limit directory recursion depth
File Size Limits¶
--max-filesize NUM+SUFFIX: Ignore files larger than this sizeSuffixes:# Skip files larger than 100KB rg --max-filesize 100K pattern # Skip files larger than 5MB rg --max-filesize 5M patternK(kilobytes),M(megabytes),G(gigabytes).
Binary Files¶
Binary detection
By default, ripgrep auto-detects binary files (by finding NUL bytes) and skips them to avoid polluting output. For detailed binary handling strategies, see Binary Data Detection.
-
--binary: Force searching binary files (shows matches even if NUL bytes detected) -
-a, --text: Treat all files as text, disabling binary detection -
Default is 150. Ripgrep checks the first NUM bytes for NUL characters to determine if a file is binary. This does not control line length detection.--max-columns-preview NUM: Set number of bytes to preview for NUL detection
Advanced Filtering¶
-
Useful to avoid searching network mounts or external drives.--one-file-system: Don't cross filesystem boundaries when searching -
By default, ripgrep traverses up and respects--no-ignore-parent: Don't respect ignore files in parent directories.gitignore/.ignorefiles in parent directories. -
Allows adding custom ignore files beyond--ignore-file PATH: Specify additional custom ignore files.gitignoreand.ignore. Useful for project-specific filtering rules. -
This is part of the granular ignore control flags, skipping exclude files while still respecting other ignore mechanisms.--no-ignore-exclude: Don't respect.git/info/excludefiles -
Useful for cross-platform scripts and consistent output formatting.--path-separator SEPARATOR: Use custom path separator in output