Skip to content

DennisLent/rgrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rgrep

coverage

rgrep-logo

rgrep is a fast, parallel, grep-like search tool written in Rust.

It’s designed as a learning project and to showcase efficient text processing, parallel file and directory traversal and a realistic, user-friendly command-line interface

The goal is not to be a drop-in replacement for grep, but to support a solid, practical subset of functionality.

Core behavior

  • Search for a pattern in one or more files, directories, or standard input.
  • Pattern syntax:
    • Regex by default
    • Fixed string optional mode
  • Streams input: no need to load whole files into memory.
rgrep PATTERN [PATH...]
# If no PATH is given, rgrep reads from stdin.

Basic options

  • -h, --help Show help message and exit.

  • --version Show version information and exit.

  • -i, --ignore-case Case-insensitive matching.

  • -F, --fixed-strings Treat the pattern as a literal string instead of a regular expression.

  • -w, --word-regexp Match only whole words.

  • -x, --line-regexp Match only whole lines (the entire line must match the pattern).

  • -v, --invert-match Select non-matching lines (inverse search).

Recursion & file selection

  • -r, --recursive Recursively search directories given in PATH.

  • --include=GLOB Only search files whose names match the given glob (e.g. --include='*.rs').

  • --exclude=GLOB Skip files whose names match the given glob (e.g. --exclude='*.log').

  • --hidden Include hidden files/directories (by default they may be skipped).

Output control

  • -n, --line-number Show line numbers with matching lines.

  • -l, --files-with-matches Print only the names of files containing matches.

  • -c, --count Print the number of matching lines per file instead of the lines themselves.

  • -q, --quiet, --silent Do not print matches; exit with status:

    • 0 if a match is found
    • 1 if no matches are found
    • 2 on error
  • --with-filename Always show the filename prefix (even if a single file or stdin).

  • --no-filename Never show the filename prefix (useful when piping into other tools).

Context lines

  • -A NUM, --after-context=NUM Print NUM lines after each matching line.

  • -B NUM, --before-context=NUM Print NUM lines before each matching line.

  • -C NUM, --context=NUM Print NUM lines of context before and after each match.

Parallelism

  • -j N, --jobs=N Number of worker threads to use.

    • N > 0: use exactly N threads.
    • If omitted: automatically choose a sensible default (e.g. number of CPU cores).
  • --no-parallel Force single-threaded mode (useful for debugging and performance comparison).

  • --stats Print simple performance statistics after the search:

    • Number of files scanned
    • Number of lines processed
    • Number of matches found
    • Approximate runtime and throughput

Colorized output

  • --color[=WHEN] Colorize matching text. WHEN can be:

    • auto (default): color only when output is a terminal
    • always: always use color
    • never: never use color

Exit codes

  • 0 – At least one match was found.
  • 1 – No matches were found.
  • 2 – An error occurred (e.g. invalid regex, unreadable file).

Usage examples

Search for “error” in a single file:

rgrep "error" app.log

Count matches from standard input:

echo -e "foo\nbar\nfoo" | rgrep -c foo

Recursive, case-insensitive search in a source tree:

rgrep -ri "panic" src/

Show line numbers and some context around matches:

rgrep -n -C 2 "TODO" src/

Literal search (no regex) and just count matching lines:

rgrep -F -c "GET /health" logs/*.log

Parallel search using 8 worker threads:

rgrep -j 8 "timeout" /var/log

Only show filenames of files that contain “unsafe”:

rgrep -rl "unsafe" src/

Search only Rust files, skipping everything else:

rgrep -r --include="*.rs" "Result<" .

Build & install

Build and run from the workspace root:

cargo build --release
# or run directly
cargo run --release -- --help          # note the extra `--` to pass args to rgrep
cargo run --release -- "panic" src/

Installation options

  • GitHub release binaries (recommended for users): download the archive for your platform from the GitHub Releases page, unpack, and place rgrep on your PATH.
  • Cargo install from the repo: cargo install --git https://github.com/DennisLent/rgrep --branch main

Benchmarking

To compare rgrep with grep on a large codebase, there is a helper script that benchmarks common workloads (counting matches, listing files with matches, word searches, etc.) on a clone of the Linux kernel:

rgrep-performance

About

Rust Implementation of Grep

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published