ripgrep (rg) 설치: 기본 정규식 검색, 자주 쓰는 플래그, grep 비교

rg 설치, 첫 regex 검색, flags 요약, grep 유지 시점.

grep -r works in a repo, but it happily walks node_modules, needs more flags for a sane default, and regex metacharacters fight the shell. ripgrep (rg, Rust, BurntSushi) recurses by default, respects .gitignore, and packs daily search into short flags. macOS/Linux 설치, 리터럴·기본 정규식, 자주 쓰는 플래그, grep 대비를 hereink·fd·bat 워크플로 기준으로 정리합니다. ignore 는 ripgrep · gitignore 글을 보세요.

검색어:ripgrep 설치 정규식 검색 grep 플래그 비교. You should finish with rg on PATH, a first search from the repo root, fluency with -n/-l/-i/-w, and when to keep /bin/grep.

installbrew · apt · dnf
searchliteral · regex
comparerg vs grep
install rgregex & flagsvs grep

What rg fixes

Repo search with fewer footguns

rg TODO recurses from here, skips ignored paths, and prints paths with line numbers. Less noise than grep -rIn TODO . on a large tree.

Works with fd and bat

fd lists paths, rg searches content, bat previews hits: rg -l pattern | xargs bat.

Upstream: github.com/BurntSushi/ripgrep. Run rg --version after install.

Install on macOS and Linux

  1. 1
    macOS (Homebrew)

    brew install ripgrep. Verify with which rg and rg --version.

  2. 2
    Debian / Ubuntu

    sudo apt update && sudo apt install ripgrep. The binary is rg.

  3. 3
    Fedora / Arch

    Fedora: sudo dnf install ripgrep. Arch: sudo pacman -S ripgrep.

  4. 4
    Windows (optional)

    winget install BurntSushi.ripgrep.MSVC or GitHub Releases. Examples below focus on macOS/Linux.

  5. 5
    First search

    At a Git root: rg "fn main" or rg TODO. Exit code 1 means no matches (not always an error in scripts).

Literals and basic regex

By default rg PATTERN treats PATTERN as a regex (Rust regex syntax). For dots and parentheses as literals, quote and escape, or use -F / --fixed-strings.

rg -F 'config.json' .
rg -F 'foo.bar' src/
rg '^import ' --type py
rg '\bError\b' logs/
rg 'function\s+(\w+)' -n app.js
rg 'TODO|FIXME' .
rg pattern src/ tests/

Common flags

rg -n pattern
rg -l pattern
rg -i pattern
rg -w Token
rg -C 3 panic
rg -t js pattern
rg -t rust 'unwrap\('
rg pattern -g '*.ts' -g '!*.min.ts'
rg -c pattern
rg -F -i 'License MIT'
rg --max-depth 2 pattern

Use --no-ignore or -u only when you mean to search ignored trees; default is safer in day-to-day dev.

rg vs grep

Goalripgrep (rg)grep
Recursive tree searchrg PATTERNgrep -rIn PATTERN .
Respect .gitignoreon by defaultnot built in
Fixed stringrg -F 'a.b'grep -F 'a.b'
Case insensitiverg -igrep -i
Files onlyrg -lgrep -rl
Context linesrg -C 3grep -C 3
Extension filterrg -t js or -g '*.js'grep -r --include='*.js'
Speedparallel, code-orientedfine for single files
POSIX minimal imagesextra installoften preinstalled

Keep /bin/grep for portable init scripts and one-off log files; use rg inside Git repos.

Good fit
Daily symbol search in repos, pairing with fd/bat, skipping vendor dirs by default.
Not ideal
Tiny containers with no extra binaries, or scripts that must stay strict POSIX—grep still wins.
Overlap with the .gitignore ripgrep article?

That post goes deep on ignore rules; this one focuses on install, regex basics, flags, and grep comparison.

Can rg replace sed for edits?

No—rg searches only. Use your editor, sd, or careful sed. rg -l first to scope files.

Why quote patterns in the shell?

Unquoted *, ?, and $() expand before rg runs. Single quotes around the pattern are the easy default.

검색 후 설계 맞추기

Module boundaries are easier on a shared board. See 공간 만들기.

지금 시작