//View Tip #46
Similar Tips
» Simple password generator
» Filter stderr for cron jobs
» Command line currency conversion
» SVN resolve all conflicts
» Change prompt color dynamically

 

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}


View Comments »




Comments 

Add your comment

Comments are currently disabled
meh
explain it please?
Posted 2009-01-02 03:10:12
jeeks
is there something similar for really long paths?
Posted 2009-03-31 12:15:24
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}
Posted 2009-03-31 12:29:26
It's very useful , tks
Posted 2010-08-24 21:31:16
FingAZ
Another example:

rm /home/username/dir{1,2,3,4,5}/file.txt

Will delete 'file.txt' from dir1, dir2, dir3, dir4 and dir5 in the user's home directory.
Posted 2010-09-25 06:20:22

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit