//View Tip #46
» Permanent bash history
» Tar remote dir over SSH
» ssh proxy forwarding
» Store a directory name to come back to
meh
Similar Tips
» swap files» Permanent bash history
» Tar remote dir over SSH
» ssh proxy forwarding
» Store a directory name to come back to
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Using expansion to move a file aside without having to type the file name twice
cp ReallyLongFileNameYouDontWantToTypeTwice{,.orig}Comments
Add your comment
#1
explain it please?
Posted 2009-01-02 03:10:12
Explanation:
This uses brace expansion to create the two filenames (orignal and backup). Brace expansion generates a list of strings with each set of characters given in the braces. For example, "echo a{d,c,b}e" will give "ade ace abe".
In this case there is a blank for the first item and the second adds ".orig" for example:
cp file{,.orig}
Becomes:
cp file file.orig
This will indeed work with directories:
cp long/path/here/file{,.orig}
This uses brace expansion to create the two filenames (orignal and backup). Brace expansion generates a list of strings with each set of characters given in the braces. For example, "echo a{d,c,b}e" will give "ade ace abe".
In this case there is a blank for the first item and the second adds ".orig" for example:
cp file{,.orig}
Becomes:
cp file file.orig
This will indeed work with directories:
cp long/path/here/file{,.orig}
Posted 2009-03-31 12:29:26

