A powerful CLI tool for batch renaming files with pattern matching, regex support, recursive directory traversal, and full undo capability.
- Pattern-based renaming — search & replace with plain text or regex
- Regex support — full JavaScript regex support (capture groups, etc.)
- Recursive mode — process subdirectories
- File extension filtering — target specific file types
- Dry-run preview — always see what will happen before anything changes
- Full undo — revert any batch rename operation
- History tracking — persistent rename history per directory
git clone https://github.com/1kai123/batch-rename-cli.git
cd batch-rename-cli
npm install
npm link # makes `batch-rename` available globallynpm install -g batch-rename-clibatch-rename <command> [options]| Command | Description |
|---|---|
pattern |
Rename files by search/replace pattern |
undo |
Undo the last batch rename operation |
history |
Show rename history for a directory |
help |
Show help message |
batch-rename pattern [options]Options:
| Short | Long | Description |
|---|---|---|
-s |
--search |
Search string or regex pattern (required) |
-r |
--replace |
Replacement string (required) |
-x |
--regex |
Treat search string as regex |
-e |
--ext |
Filter by file extension (e.g. .jpg) |
-d |
--dir |
Target directory (default: current directory) |
-R |
--recursive |
Recursively process subdirectories |
-c |
--confirm |
Actually rename (default: dry-run preview only) |
Replace IMG_ with photo_ in all .jpg files:
batch-rename pattern --search "IMG_" --replace "photo_" --ext .jpgbatch-rename pattern --search "IMG_" --replace "photo_" --ext .jpg --confirmRename photo001.jpg → img-001.jpg:
batch-rename pattern --search "^photo(\\d+)" --replace "img-$1" --regex --ext .jpg --confirmbatch-rename pattern --search "_old" --replace "_new" --recursive --confirmbatch-rename undoUndo the last 2 operations:
batch-rename undo --steps 2batch-rename history- Dry-run by default — the tool always shows a preview first, so you can verify before anything changes
- History file — a
.batch-rename-history.jsonis created in each processed directory, tracking every rename operation - Undo — uses the history file to reverse renames in the correct order
MIT