Bash Curly Brace Expansion

Bash/Zsh curly-brace expansion is simple but powerful: each permutation enclosed in braces is expanded, recursively, before glob expansion:

$ echo a{b,c,d{e,f}}g
abg acg adeg adfg

This is handy if you’re renaming files far from your working directory:

$ mv some/long/path/Xyz.{foo,bar} 

Which is equivalent to the longer, and decidedly less pleasant-to-type:

$ mv some/long/path/ some/long/path/

Another good use for brace expansion is to create a complete directory tree in one command:

$ mkdir -p src/{main,test}/java/org/foo/bar

To play with and understand complex brace expansions, use echo:

$ echo mkdir -p src/{main,test}/java/org/foo/bar
mkdir -p src/main/java/org/foo/bar src/test/java/org/foo/bar