smart grouping shorten long command line
August 25th, 2006 mysurface Posted in curly brackets, Symbol | Hits: 21506 | 4 Comments »
Let say you want to copy certain files from a directory to current directory, which the parent path is long, how the command will looks like?
cp /home/foobar/downloads/one /home/foobar/downloads/two..... .
So most of the people will change directory to downloads first, then copy those files, such as
(Assume the current directory is /home/soomee/downloads )
cd /home/foobar/downloads
cp one two three four five /home/soomee/downloads
That is another alternative way, use curly bracket { }
cp /home/foobar/downloads/{one,two,three,four} .
This command line is much much shorter and it is also very clean.
Another example, which is where I learn the grouping from, when I need to compile my source code in hello.c to executable file hello, I do this
gcc -o hello hello.c
Okay, and it become like that.
gcc -o hello{,.c}
The curly bracket can be used at infront too, let say i want to backup my .vimrc i can do this
cp {,bk}.vimrc
This is equivalent to this
cp .vimrc bk.vimrc
ï¼»ä¸æ–‡ç¿»è¯‘ï¼½







December 24th, 2006 at 9:16 am
A formal name for this feature is “Brace Expansion”, I just found it recently in Bash Reference Manual, or you may try
man bashthen search for “brace expansion”.January 27th, 2007 at 4:40 am
[...] I like to do this, combine with curly brackets [...]
June 19th, 2007 at 8:46 pm
[...] This post is to illustrate additional usage of curly brackets { } for range of numbers, continues from smart grouping shorten long command line. [...]
June 19th, 2007 at 11:29 pm
[...] This post is to illustrate additional usage of curly brackets { } for range of numbers, continues from smart grouping shorten long command line. [...]