Created
March 25, 2026 00:27
-
-
Save Opfour/7b2329555b649075f63ee3e8e1d5d775 to your computer and use it in GitHub Desktop.
common ripgrep search commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ● Here are the most useful rg patterns: | |
| Basic text search | |
| rg "search term" # search current dir recursively | |
| rg -i "search term" # case insensitive | |
| rg -w "word" # whole word match only | |
| rg "exact phrase here" # phrase search | |
| File filtering | |
| rg "term" -t py # only Python files | |
| rg "term" -t js -t ts # multiple file types | |
| rg "term" -T html # exclude HTML files | |
| rg "term" -g "*.yml" # custom glob filter | |
| rg "term" -g "!*.log" # exclude glob pattern | |
| Find files by name (like find) | |
| rg --files | rg "config" # find files with "config" in name | |
| rg --files -g "*.toml" # find all TOML files | |
| rg --files -g "Makefile" # find specific filename | |
| Context around matches | |
| rg -C 3 "term" # 3 lines before & after | |
| rg -B 2 "term" # 2 lines before | |
| rg -A 5 "term" # 5 lines after | |
| Useful flags | |
| rg -l "term" # list filenames only (no content) | |
| rg -c "term" # count matches per file | |
| rg -n "term" # show line numbers (default) | |
| rg --hidden "term" # include dotfiles | |
| rg -z "term" # search compressed files | |
| rg -m 1 "term" # first match per file only | |
| Regex | |
| rg "func\w+\(" # functions starting with "func" | |
| rg "TODO|FIXME|HACK" # multiple patterns | |
| rg "^\s*import" # lines starting with import | |
| rg "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" # IP addresses | |
| Specific directories | |
| rg "term" ~/ferrite/ # search specific path | |
| rg "term" src/ tests/ # multiple directories | |
| rg -g "!node_modules" "term" # exclude a directory | |
| Pro tip: rg --type-list shows all built-in file types it recognizes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment