r/CLI•
Ops_Mechanic

Make a backup of any file without typing the filename twice

TIL you can make a backup of any file without typing the filename twice

Instead of:

cp config.yml config.yml.bak

Just write:

cp config.yml{,.bak}

The shell expands `config.yml{,.bak}` into `config.yml config.yml.bak` before cp even sees it. The empty string before the comma is the original, `.bak` is the suffix.

Bonus: throw a datestamp in there:

cp config.yml{,.$(date +%F)}

Outputs something like `config.yml.2026-02-21`. Now your backups are timestamped and you can stop naming things `config.yml.bak.bak.old.final`.

Works in bash and zsh. Been using this for years and it still saves me a keystroke every single time.

Posted Feb 21, 2026, 5:36 PM UTC

1147
Loading comments…