CLI tool written in Go to search and replace text in files recursively with backup/restore functionality.
go-replace is a powerful text replacement tool that allows you to:
- Replace text patterns in files across directories
- Create automatic
.bak
backups - Restore original files from backups
- Clean up backup files
- 🔄 Text Replacement - Replace strings in all matching files
- 💾 Backup System - Auto-create
.bak
files before modification - ⏮️ ** Restore System** - Revert files from backups
- 🧹 Clean Backups - Delete all
.bak
files - 📁 Pattern Matching - Target files using wildcard patterns
# Clone repository
git clone https://github.com/arwahdevops/go-replace.git
cd go-replace
# Build and install
go build -o go-replace
sudo mv go-replace /usr/local/bin/
go install github.com/arwahdevops/go-replace@latest
sudo cp $HOME/go/bin/go-replace /usr/local/bin/
go-replace [OPTIONS] -old "OLD_TEXT" -new "NEW_TEXT"
Flag | Description |
---|---|
-dir |
Target directory (default: current) |
-pattern |
Filename pattern (e.g., *.txt) |
-old |
Text to replace (required) |
-new |
Replacement text (required) |
-backup |
Create backup files |
-restore |
Restore files from .bak backups |
-clean |
Delete all .bak files |
go-replace -dir docs -pattern "*.md" -old "foo" -new "bar"
go-replace -dir src -old "http://" -new "https://" -backup
go-replace -dir project -restore
go-replace -dir data -clean
-
Backup Safety
- Backup files (
*.bak
) are created in the same directory - Original file permissions are preserved
- Backup files (
-
Pattern Matching
- Supports standard wildcard patterns:
*
matches any sequence?
matches any single character
- Supports standard wildcard patterns:
-
Safety First
- Double-check replacement patterns before execution
- Always use
-backup
for critical operations
This project is licensed under the MIT License - see the LICENSE file for details.