rg — Searching
Pattern Search
rg 'root' /etc/passwd
Expected output:
1:root:x:0:0::/root:/bin/bash
rg prints line numbers by default, highlights matches in color. No flags needed for the common case.
rg -i 'antora' ~/atelier/_bibliotheca/domus-captures/docs/
-i maps to grep -i. Searches recursively by default — no -r flag needed.
rg -w 'log' /etc/passwd
Without -w, log matches syslog, dialogd, catalog. With -w, only whole-word boundaries match. Equivalent to grep -w or wrapping the pattern in \b…\b.
rg -F '$$' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages/
-F treats the pattern as a literal string. Essential when searching for regex metacharacters ($, ., *, +, ?, [, {) without escaping each one.
rg -v '^#' /etc/fstab
Prints every line that does NOT match the pattern. Here: all uncommented lines in fstab.
rg -c 'include::' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/pages/codex/grep/
Expected output:
basics.adoc:3
index.adoc:0
gotchas.adoc:2
pcre.adoc:2
Reports count per file. Files with 0 matches are shown too (unlike grep -c which omits them by default with -r).
rg -m 1 'nologin' /etc/passwd
Stops after the first match in each file. Useful for existence checks in large trees.
cat <<'EOF' > /tmp/rg-multiline-test.txt
function setup() {
echo "init"
}
EOF
rg -U 'function.*\{[\s\S]*?\}' /tmp/rg-multiline-test.txt
-U enables multiline mode. [\s\S]*? matches anything including newlines (non-greedy). Without -U, . never matches \n and patterns cannot span lines.
if rg -q 'PermitRootLogin' /etc/ssh/sshd_config; then
echo "PermitRootLogin directive found"
else
echo "PermitRootLogin directive missing"
fi
-q suppresses all output. Exit code 0 = match found, 1 = no match, 2 = error. Same semantics as grep -q.
rg -e 'TODO' -e 'FIXME' -e 'HACK' ~/atelier/_bibliotheca/domus-captures/docs/modules/ROOT/partials/
Each -e adds an alternative pattern. Lines matching ANY pattern are printed. Equivalent to grep -e 'A' -e 'B' or rg 'TODO|FIXME|HACK' — but -e is cleaner when patterns contain regex metacharacters.