Speedy, multithreaded command line(CLI) search utility written in Rust for Windows. SearchToolCLI includes recursive traversal of directories, performs fast regex free substring & pipe delimited pattern matching, measures the single threaded vs multithreaded execution speed, with an installer for PowerShell, initialising s4 / S4 shortcut with structured PowerShell Format-Table output on first launch.
-
Multithreaded File Scanning: Scales working threads dynamically using
std::thread::available_parallelism()and shares a read only search configuration safely across threads withArc<SearchConfig>. -
Case-Insensitive Matching (
-i): Support for both case sensitive and case insensitive searches without regular expression overhead. -
Pipe-Delimited Alternation (
|): Matches multiple patterns in just a single pass (e.g.,"attack|network|work"), reporting each matching line only once. -
Built-In Performance Benchmarking: Compares a single threaded (
1thread) vs multithreaded (Nthreads) execution time withstd::time::Instantand prints the metrics tostderr. -
Automatic PowerShell
s4/S4Integration: On the first launch on Windows,SearchToolCLIwill install thes4shortcut functionality into your PowerShell$PROFILE(WindowsPowerShell\Microsoft.PowerShell_profile.ps1) so that it can format search results cleanly viaFormat-Table.
SearchToolCLI/
├── src/
│ └── main.rs # CLI argument parser, directory crawler, concurrent search, and PS profile installer
├── install.ps1 # One-command release build and PowerShell profile setup script
├── Cargo.toml # Crate manifest (zero external dependencies)
├── Cargo.lock
└── README.md
-
Rust Toolchain:
rustcandcargo(2021 edition or newer) -
Operating System: Windows 10 / 11 with PowerShell 5.1+ (for automatic
s4/S4profile integration)
Clone the repository and dot-source the included PowerShell installer:
git clone <your-repo-url>
cd SearchToolCLI
. .\install.ps1Important: Include the leading dot and space (
. .\install.ps1). This runs the script in your current session sos4andS4are available immediately without restarting PowerShell.
The installer automatically:
- Compiles the optimized release binary (
.\target\release\SearchToolCLI.exe). - Runs
SearchToolCLI.exe --installto register thes4(and case-insensitiveS4) table-formatted function in your PowerShell$PROFILE. - Reloads
$PROFILEsos4works right away in your current terminal and in every future PowerShell session from any directory.
(If you run .\install.ps1 without the leading dot, the build and profile setup still succeed—just open a new PowerShell window or run . $PROFILE once to activate s4.)
If you prefer to build manually without the script:
cargo build --release
.\target\release\SearchToolCLI.exe --install
. $PROFILERunning .\target\release\SearchToolCLI.exe directly on any search also triggers the first-launch profile installer automatically.
Note: On first launch,
SearchToolCLIdelegates the profile write topowershell.exeso it works cleanly even when Windows Security Controlled Folder Access restricts direct writes to theDocumentsfolder. Subsequent runs check for the# >>> SearchToolCLI s4/S4 <<<marker and skip the installer completely.
The s4 function wraps SearchToolCLI.exe and formats every match into a wrapped table (File, Line, Text):
# Case-sensitive search
s4 "search-term/pattern" "C:\User\Example\Path\DeskTop"
# Case-insensitive search (-i)
s4 -i "SEARCH-TERM/PATTERN" "C:\USER\EXAMPLE\PATH\DOWNLOADS"
# Pipe-delimited OR alternation with case-insensitivity
S4 -i "attack|network|work" "C:\USER\EXAMPLE\PATH"Example Table Output:
File Line Text
---- ---- ----
Anonymous Networking.txt 5 Malicious and Colluding Relays (Sybil Attacks)
The attacks detailed in your study.txt 1 The attacks detailed in your study guide...
You can also invoke SearchToolCLI.exe directly for raw path:line:content output:
.\target\release\SearchToolCLI.exe [-i] "<pattern>" "<file_or_dir>"To inspect only the single-threaded vs. multithreaded timing metrics on stderr, redirect stdout to $null:
.\target\release\SearchToolCLI.exe -i "SEARCHCONFIG|PUB FN" .\bench_tmp > $nullTested on Windows (8 logical threads) across a synthetic dataset of 500 files / 100,000 lines using -i "SEARCHCONFIG|PUB FN":
| Execution Mode | Matches Found | Elapsed Time | Speedup |
|---|---|---|---|
Single-threaded (1 thread) |
2,500 | 138.59 ms |
1.00x (baseline) |
Multithreaded (8 threads) |
2,500 | 33.01 ms |
~4.20x |
-
Argument Parsing (
parse_args): Extracts the optional-iflag, search pattern, and target path fromstd::env::args(). -
Recursive Traversal (
collect_files): Walks the target path and collects all regular filePathBufentries. -
Chunked Parallel Search (
search_concurrent): Splits the file list into balanced chunks across worker threads, reads files line-by-line viaBufReader, and evaluates patterns with zero external regex dependencies. -
Profile Automation (
ensure_powershell_shortcuts): Checks for the# >>> SearchToolCLI s4/S4 <<<marker inMicrosoft.PowerShell_profile.ps1and appends thes4wrapper function once viapowershell.exeif absent.
I have added to the repo is a copy of The Rust Programming Language by Steve Klabnik and Carol Nichols, with contributions from the Rust Community. Provided as a reference with explanations of some of the core Rust concepts used in this project—including ownership, borrowing, error handling (Result / io::Result), Arc for thread safe shared state and multithreaded concurrency using std::thread.