fastmod
Perform bulk code changes quickly, safely
TLDR
Replace a regex in all files of the current directory, ignoring files on .ignore and .gitignore
Replace a regex in case-insensitive mode in specific files or directories
Replace a regex in a specific directory in files filtered with a case-insensitive glob pattern
Replace for an exact string in .js or JSON files
Replace for an exact string without prompt for a confirmation (disables regex)
Replace for an exact string without prompt for a confirmation, printing changed files
SYNOPSIS
fastmod [OPTIONS] <FROM> <TO> [<PATH> ...]
PARAMETERS
-h, --help
Print help information
-V, --version
Print version information
-i, --ignore-case
Ignore case distinctions in patterns
-l, --files-with-matches
Print paths of files with matches
-n, --count
Count occurrences of FROM in files
--print
Print paths that would be modified (dry run)
--null
Use NUL as path separator
--path-separator <SEP>
Set custom path separator
--regex-flags <FLAGS>
Apply RE2 regex flags (e.g., 'i' for case-insensitive)
-r, --repl <REPL>
Replacement text (overrides TO argument)
-v, --verbose
Enable verbose logging
--cwd <PATH>
Change working directory
--backup-ext <EXT>
Backup files with given extension before modifying
DESCRIPTION
Fastmod is a high-performance command-line utility designed for in-place search and replace operations across large numbers of files, particularly useful in codebases and directories with thousands of files. Developed by Andrew Gallant (BurntSushi), the creator of ripgrep, it leverages Rust's speed and parallelism to outperform traditional tools like sed -i or perl -pi by orders of magnitude on large repositories.
It uses RE2 regex syntax for pattern matching, ensuring safety and predictability compared to more complex engines. Fastmod reads the 'from' pattern and 'to' replacement from command-line arguments, scans specified paths (or current directory recursively), and performs substitutions directly in files. It supports case-insensitive matching, counting matches without replacement, listing affected files, and dry-run previews.
Key advantages include parallel processing, efficient directory traversal akin to ripgrep, and minimal memory usage. It's ideal for refactoring code, updating configurations, or bulk text edits. However, it skips binary files, hidden files by default (configurable), and provides safeguards like backups via --backup. Install via Cargo: cargo install fastmod.
CAVEATS
Uses RE2 regex (no backreferences in replacements); skips binary/hidden files by default; no multiline regex support; requires write permissions on targets.
REGEX SYNTAX
RE2 syntax: Perl-like but safe. Supports capture groups in FROM; use $1 in TO for backrefs.
Example: fastmod 'old(text)' 'new\$1' file.txt
PERFORMANCE
Excels on large repos (e.g., 10x faster than sed on Chromium src). Uses SIMD, threading; benchmarks on GitHub.
HISTORY
Released in 2019 by BurntSushi as a faster sed alternative. Actively maintained on GitHub; v0.3+ added backup support and improved parallelism.


