As man mkdir states

   -p, --parents
          no error if existing, make parent directories as needed

When I ran this command

mkdir -p work/{F1,F2,F3}/{temp1,temp2}

It creates a folder structure like this work parent folder then F1,F2,F3 child folders and temp1 and temp2 child folders under three parent folder F1,F2,F3.


Now the problem is that I want to create temp1,temp2 folders only under F1 not under F2 and F3, but I'm confused on how I can write a command to do what I want.

  • @Caleb: sorry, I was not aware we were both editing at the same time, it seems that revision merging is not implemented by SE :-/ – Stéphane Gimenez Aug 2 '11 at 13:48
  • @Stephane: No worries. I've made a lot of edits and it's pretty rare that two major edits get clobbered like that. Thanks for contributing! – Caleb Aug 2 '11 at 13:52
up vote 22 down vote accepted

Maybe this is what you are looking for?

 mkdir -p work/{F1/{temp1,temp2},F2,F3}
  • Hey, I was wondering recently if things could be done as simple as that. Thanks! – rozcietrzewiacz Aug 2 '11 at 13:55

A very good description of brace expansion (with examples) can be found at subsection Brace Expansion of bash manual (man bash, press / to start search and search for Brace Expansion).

  • Thank you, your answer led me to this great guide! Just needed to know that it's called "Brace Expansion" so I knew what to google. Excerpt: "Perhaps the strangest expansion is called brace expansion. With it, you can create multiple text strings from a pattern containing braces. Here's an example: [me@linuxbox me]$ echo Front-{A,B,C}-Back Front-A-Back Front-B-Back Front-C-Back" – Rock Lee Jun 6 at 20:13

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.