Linux command
fastmod 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Replace a string interactively
fastmod "[old_string]" "[new_string]"
Replace using a regex
fastmod -m "[pattern]" "[replacement]"
Replace in a specific directory
fastmod "[old]" "[new]" [path/to/directory]
Replace only in files
fastmod -e "[py,js]" "[old]" "[new]"
Accept all replacements
fastmod --accept-all "[old]" "[new]"
Preview matches
fastmod --print-only "[old]" "[new]"
Treat pattern as a literal string
fastmod --fixed-strings "[old.string()]" "[new.string()]"
说明
fastmod performs fast, interactive codemod operations across files. It searches for regex patterns and prompts for confirmation before each replacement, making bulk code changes safer. The tool uses the same regex engine as ripgrep for fast searching combined with interactive review of changes. By default, patterns are treated as regular expressions. If no replacement is given, fastmod deletes the matched text. If no paths are given, it searches the current directory recursively. During interactive mode, press y to accept, n to skip, e to edit the replacement, a to accept all remaining, or q to quit.
参数
- -m, --multiline
- Enable multiline regex matching (dot matches newlines).
- -i, --ignore-case
- Case insensitive matching.
- -e, --extensions _exts_
- Comma-separated list of file extensions to process (e.g., py,js,ts).
- --accept-all
- Apply all replacements without interactive prompting.
- --print-only
- Show matches without modifying files.
- -d, --dir _path_
- Set the root search directory (default: current directory).
- --glob _pattern_
- Include/exclude files by glob pattern (prefix with ! to exclude).
- --hidden
- Include hidden files and directories in the search.
- --fixed-strings, -F
- Treat the pattern as a literal string, not a regex.
- --count
- Display the total number of matches/replacements.
FAQ
What is the fastmod command used for?
fastmod performs fast, interactive codemod operations across files. It searches for regex patterns and prompts for confirmation before each replacement, making bulk code changes safer. The tool uses the same regex engine as ripgrep for fast searching combined with interactive review of changes. By default, patterns are treated as regular expressions. If no replacement is given, fastmod deletes the matched text. If no paths are given, it searches the current directory recursively. During interactive mode, press y to accept, n to skip, e to edit the replacement, a to accept all remaining, or q to quit.
How do I run a basic fastmod example?
Run `fastmod "[old_string]" "[new_string]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -m, --multiline do in fastmod?
Enable multiline regex matching (dot matches newlines).