bak

View script Copied!

Rename files in place by appending .bak to the name. When the .bak version already exists, it rotates recursively (file.bakfile.bak.bakfile.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.

Quick start

$ bak config.yaml
$ ls config*
config.yaml.bak

Common examples

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

Reference

All options

Flag Description
-v, --verbose Print filenames as they are backed up
-n, --dry-run Simulate actions without making changes
-h, --help Display help

Exit codes

Code Meaning
0 Success
1 Runtime failure (source file missing, mv failed)
2 Usage error (unknown option)

Behavior