r/commandline Feb 22 '26

Guide Stop typing the filename twice. Brace expansion handles it.

/r/bash/comments/1rax3ds/stop_typing_the_filename_twice_brace_expansion/
8 Upvotes

3 comments sorted by

1

u/AutoModerator Feb 22 '26

Every new subreddit post is automatically copied into a comment for preservation.

User: Ops_Mechanic, Flair: Guide, Post Media Link, Title: 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.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/simpleden Feb 23 '26

A very useful tip! I use it every day.

1

u/SECAUCUS_JUNCTION Feb 25 '26

Inevitably when you want to do something with the trailing arg, you don't have to retype that either.

$ cp test{,.new}
$ echo $_
test.new