Shell – Using curly brackets (braces) to create folder structure with `mkdir -p`

brace-expansionshell

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.

   work
     -F1
       -temp1
       -temp2
     -F2
       -temp1
       -temp2
     -F3
       -temp1
       -temp2

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.

Best Answer

Maybe this is what you are looking for?

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