UNIX: Shortcut to create a backup copy of a file

Contributor Icon Contributed by barretj  
Tag Icon Tagged: UNIX  

Copy and rename a file in a shorter step than the normal cp file file.bak


If you have a file named foobar and you want to make a backup copy named foobar.bak you could do

cp foobar foobar.bak

but what if the file has a long name, and you have a similarly named file so tab-expansion wont work?

Here’s what you can do instead:

cp foobar{,.bak}

the shell will automagically expand this to cp foobar foobar.bak

note: I tested this in bash and zsh, other shells may or may not work

 

No Comments -


No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment -