# ripgrep (rg) — Recursively Search Directories with Regex > ripgrep recursively searches directories for a regex pattern while respecting your gitignore. Written in Rust, ripgrep is the fastest search tool on the market — used inside VS Code, GitHub, and many other dev tools. ## Install Save as a script file and run: ## Quick Use ```bash # Install brew install ripgrep # macOS sudo apt install ripgrep # Debian/Ubuntu cargo install ripgrep # From source ``` Basic usage: ```bash rg pattern # Search cwd recursively rg -i pattern # Case-insensitive rg "pattern" --type js # Only .js files rg -l pattern # List files with match rg -C 3 pattern # 3 lines of context rg pattern -g "!node_modules/*" # Exclude dir rg -r "\$1" "console.log\((.+)\)" # Regex capture replace rg --json pattern | jq # JSON output ``` ## Intro ripgrep (binary name `rg`) is a line-oriented search tool that recursively searches directories for a regex pattern while respecting your .gitignore. Written in Rust by Andrew Gallant (BurntSushi), it combines the raw speed of grep with the usability of ag/ack. The search engine inside VS Code, GitHub code search, Helix editor, and many others. - **Repo**: https://github.com/BurntSushi/ripgrep - **Stars**: 62K+ - **Language**: Rust - **License**: Unlicense/MIT (public domain) ## What ripgrep Does - **Recursive search** — walks directory tree - **Gitignore aware** — skips .gitignore, .ignore, global ignore - **Smart case** — `--smart-case` for case-insensitive when all lower - **File types** — `--type js` or `--type-add` custom - **Globs** — `-g` include/exclude patterns - **Regex** — full Rust regex engine (PCRE2 with `-P`) - **Context** — `-A`/`-B`/`-C` lines around matches - **Output** — text, JSON, vimgrep, colored - **Parallelism** — multi-threaded by default ## Architecture Single Rust binary. Uses memchr + SIMD for byte-level search, regex crate for patterns. Walks filesystem in parallel (one thread per CPU). Respects .gitignore via the ignore crate. ## Self-Hosting CLI tool, self-contained binary. ## Key Features - Fastest grep alternative (sometimes 10x faster than grep) - Gitignore/ignore respect - Parallel search - JSON output mode - File type filters - Unicode aware - PCRE2 support (with `-P`) - Replace mode (`-r`) - Integrates with VS Code, Helix, Zed, IntelliJ ## Comparison | Tool | Language | Gitignore | Speed | Regex | |---|---|---|---|---| | ripgrep (rg) | Rust | Yes | Fastest | Rust regex + PCRE2 | | The Silver Searcher (ag) | C | Yes | Fast | PCRE | | ack | Perl | No (manual) | Slow | Perl regex | | grep | C | No | OK | POSIX/PCRE | | git grep | C | Git-aware | Fast | Git regex | ## 常见问题 FAQ **Q: 和 grep 比快多少?** A: 一般 2-10 倍。大仓库(Linux kernel 级)差距更大,因为 ripgrep 并行且跳过 .gitignore。 **Q: 能搜隐藏文件?** A: 默认跳过。加 `-.` 或 `--hidden` 启用。 **Q: 为什么是公共领域许可?** A: 作者 BurntSushi 的选择。Unlicense 等同于放弃版权,完全自由使用。 ## 来源与致谢 Sources - GitHub: https://github.com/BurntSushi/ripgrep - License: Unlicense/MIT --- Source: https://tokrepo.com/en/workflows/85b6bce8-35bd-11f1-9bc6-00163e2b0d79 Author: Script Depot