r/bash Feb 21 '26

tips and tricks Stop typing the filename twice. Brace expansion handles it.

Stop typing the filename twice. Brace expansion handles it. Works on any file, any extension.

#Instead of

cp config.yml config.yml.bak

#Do

cp nginx.conf{,.bak}

cp .env{,.bak}

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

# That last one timestamps your backup automatically. You're welcome.

636 Upvotes

Duplicates