pt
Find files matching a pattern
TLDR
Find files containing "foo" and print the files with highlighted matches
Find files containing "foo" and display count of matches in each file
Find files containing "foo" as a whole word and ignore its case
Find "foo" in files with a given extension using a regex
Find files whose contents match the regex, up to 2 directories deep
SYNOPSIS
pt [OPTIONS] PATTERN [PATH...]
PARAMETERS
-i, --ignore-case
Ignore case distinctions in the pattern and input files.
-S, --smart-case
Ignore case if the pattern contains no uppercase characters; otherwise, match case.
-w, --word-regexp
Force the pattern to match only whole words.
-Q, --literal
Treat the pattern as a literal string, escaping any regular expression metacharacters.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-l, --files-with-matches
Only print the names of files that contain matches, one per line.
-L, --files-without-matches
Only print the names of files that do not contain matches, one per line.
-C NUM, --context=NUM
Print NUM lines of context around matches.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matches.
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matches.
-p PATTERN, --path-regexp=PATTERN
Only search files whose path matches the given regular expression PATTERN.
-g PATTERN, --file-regexp=PATTERN
Only search files whose name matches the given regular expression PATTERN.
-a, --all-files
Search all files, including hidden and ignored files (those typically ignored by .gitignore).
-j NUM, --jobs=NUM
Number of search workers to use. Defaults to the number of CPU cores.
DESCRIPTION
The Platinum Searcher (pt) is a powerful command-line tool designed for ultra-fast code searching across large codebases. It serves as a modern alternative to traditional tools like grep, ack, and ag (The Silver Searcher), offering significant speed improvements by leveraging concurrent processing. Written in Go, pt intelligently navigates file systems, respecting .gitignore and .ptignore rules to automatically skip irrelevant files and directories. It supports various search patterns, including regular expressions and literal strings, and provides options for filtering by file type, path, and context control. Its primary advantage lies in its ability to quickly locate code snippets within vast projects, making it an indispensable tool for developers working on large software repositories.
CAVEATS
pt is not a standard Linux utility and must be installed separately. While highly optimized for speed, its parallel processing can consume significant CPU resources on very large codebases. Its regular expression syntax follows Go's standard library, which might have minor differences from GNU grep's regex flavor.
CONFIGURATION AND IGNORING FILES
pt intelligently respects common version control ignore files. It automatically skips files and directories specified in .gitignore, .hgignore, and its own specific ignore file, .ptignore. The .ptignore file takes precedence over others, allowing for fine-grained control over what gets searched.
PERFORMANCE OPTIMIZATION
A core design principle of pt is speed. It achieves its high performance by utilizing multiple CPU cores through Go's Goroutines for parallel file processing and optimized I/O operations. This allows it to outperform many traditional search tools, especially when dealing with massive repositories containing millions of lines of code.
HISTORY
The Platinum Searcher (pt) was created by monochromegane (Yasuhiro Matsumoto), inspired by similar code search tools like ack and ag (The Silver Searcher). It was developed with a primary focus on speed and efficiency for large codebases, leveraging the Go programming language's powerful concurrency features. Since its inception, it has gained popularity among developers for its ability to quickly navigate and search through extensive software projects, making it a valuable addition to many development workflows.