ug
Search files for patterns
TLDR
View documentation for the original command
SYNOPSIS
ug [OPTION...] [PATTERN] [FILE...]
ug [OPTION...] [-e PATTERN | -f FILE] [FILE...]
PARAMETERS
-i
Ignore case distinctions
-v
Invert match (select non-matching lines)
-r -R
Recursive search in directories
-l
Output only filenames containing matches
-c
Print count of matching lines per file
-n
Prefix lines with numbers
-H
Always print filename headers
-o
Show only the part of a line matching PATTERN
-C NUM, --context=NUM
Print NUM lines of context
-B NUM
Print NUM lines before match
-A NUM
Print NUM lines after match
-z
Treat input as null-delimited
--json
JSON output format
-Z
Add \0 after filename
-F
Literal strings, no regex
-w
Match whole words only
--files-with-matches
Files only, like -l
-g PAT
Grep files matching PAT
--sort=KEY
Sort results by KEY (relevance, bestmatch)
-M SIZE
Limit memory usage
DESCRIPTION
ugrep (often aliased as ug) is a highly efficient command-line tool for searching files and directories using regular expressions. It surpasses traditional grep in speed and features, leveraging advanced algorithms like hyperscan and PCRE2 for pattern matching. ugrep supports recursive searches, compressed files, binary data, and archives without extraction. It offers grep-compatible syntax plus enhancements like context control, JSON/XML output, color highlighting, and parallel processing. Ideal for large codebases or log files, it minimizes I/O with lazy reading and SIMD instructions. Install via package managers like apt (sudo apt install ugrep) or brew.
CAVEATS
Not installed by default; requires compilation or package. Some options differ subtly from grep. High performance needs modern CPU.
PERFORMANCE TIPS
Use -j NUM for parallel jobs; -k for mmap on large files. Combine with --prelude=PAT for multi-pattern.
OUTPUT FORMATS
Supports --format=cbind,json,xml for structured data export.
HISTORY
Developed by Ruud Koot starting 2018. Version 3.x+ adds AI relevance scoring and fuzzy matching. Actively maintained, outperforms grep on large datasets.


