View script Copied!
Rename files in place by appending .bak to the name. When the .bak version already exists, it rotates recursively (file.bak → file.bak.bak → file.bak.bak.bak), so the single-.bak file is always the most recent backup.
Useful before editing a config file by hand, destructive operations on production code, or anytime you want a quick snapshot without involving git.
$ bak config.yaml
$ ls config*
config.yaml.bak
Multiple files at once:
bak database.sql server.conf
Dry-run to see what would happen first:
$ bak --dry-run report.pdf
[DRY][bak] Would move: 'report.pdf' -> 'report.pdf.bak'
Verbose to see each rename:
$ bak -v notes.txt
bak: Moving notes.txt -> notes.txt.bak
Existing .bak rotates automatically:
$ bak config.yaml # first time
$ ls config*
config.yaml.bak
$ bak config.yaml # second time
$ ls config*
config.yaml.bak config.yaml.bak.bak
| Flag | Description |
|---|---|
-v, --verbose |
Print filenames as they are backed up |
-n, --dry-run |
Simulate actions without making changes |
-h, --help |
Display help |
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Runtime failure (source file missing, mv failed) |
| 2 | Usage error (unknown option) |
[ERR][bak] file: No such file