//View Tip #46
Similar Tips
» Vi mode in bash
» Keeping your Home Directory Organized
» Manipulate Bash sockets using /dev/tcp
» User input timeout
» Command line currency conversion


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 »


Add your comment

Comments are currently disabled
explain it please?
Posted 2009-01-02 03:10:12
is there something similar for really long paths?
Posted 2009-03-31 12:15:24

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}
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
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