Monday, June 27, 2011

mkdir -p "trick"

Had no idea you could do this:

mark@pc:~/tmp/x$ mkdir -p src/{main,test}/{scala,java,resources}
mark@pc:~/tmp/x$ find .
.
./src
./src/main
./src/main/java
./src/main/resources
./src/main/scala
./src/test
./src/test/java
./src/test/resources
./src/test/scala

Awesome. Discovered here.

Update: 2011-08-25

I was wondering why this wasn't mentioned on the mkdir man page: the reason is it's a general bash thing for generating strings called brace expansion.

$ echo foo{bar,baz,boo}
foobar foobaz fooboo