Unix making directory trees

Discussion in 'Linux, BSD and Other OS's' started by Swansen, Dec 2, 2008.

  1. Swansen

    Swansen The Ninj

    Likes Received:
    0
    Trophy Points:
    36
    I know there is the
    if your in your home directory, and there is also the
    But what if i want to make multiple directories in a directory?? using THIS tree for example, how would i make that?
     
  2. Anti-Trend

    Anti-Trend Nonconformist Geek

    Likes Received:
    118
    Trophy Points:
    63
  3. Swansen

    Swansen The Ninj

    Likes Received:
    0
    Trophy Points:
    36
    no, i was using it as an example, as if it that tree were folders, how would the command look to make that tree.
     
  4. RHochstenbach

    RHochstenbach Administrator

    Likes Received:
    26
    Trophy Points:
    48
    I think that you need to browse to the directory where you want to create multiple folders. For example:
    Code:
    cd /folder1
    And then create every folder seperately.
    Code:
    mkdir 01
    mkdir 02
    mkdir 03
    
     
  5. Anti-Trend

    Anti-Trend Nonconformist Geek

    Likes Received:
    118
    Trophy Points:
    63
    Actually, Swansen actually had it better already:
    Code:
    mkdir -p work/homework/ch1/ch2
    ...that would make 'work', and the sub-dir 'ch1', and the sub-sub-dir 'ch2', all in one command.

    To answer the question, the only thing I can think of would be a 'for' loop. In other words, simple scripting. But it'd be a pretty unusual situation when you'd need to do something like that, hence my relative ignorance... out of curiosity, what are you trying to do?
     
  6. sabashuali

    sabashuali Ani Ma'amin

    Likes Received:
    6
    Trophy Points:
    38
    Just out of curiosity - do you issue the
    after you already created
    ?

    Or is the first command doing both actions in one go, i.e. creating the parent directory work/homwork and then two sub directories ch1 and 2?

    If so, how does it know which is the parent directory? work, homework, ch1 or ch2?

    Cheers! :cool:
     
  7. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    you can build the whole tree in one command:

    I know you could do

    Code:
    mkdir -p parent/{child1,child2}
    but had a shot in the dark with the version below, which worked perfect

    Code:
    mkdir -p com/pisoftware/{people{/bmarshal,/jparker},group{/dev,/sysadmin}}
     
  8. Swansen

    Swansen The Ninj

    Likes Received:
    0
    Trophy Points:
    36
    Specifically, i need to make the tree in the attachment. I did what donkey did only without the &&, so that was the missing link there. I found something similar to what Sniper is using there, but i was unsure of how to use the brackets. () I'm guessing they designate subfolders??
     

    Attached Files:

  9. donkey42

    donkey42 plank

    Likes Received:
    9
    Trophy Points:
    38
    i havn't tested it but we were both thinking alike
    Code:
    cd ~/
    mkdir -p /temp /professional/courses/major/cs381/labs /professional/courses/major/cs381/notes /professional/courses/major/cs381/programs /professional/courses/major/cs213 /professional/courses/major/cs475 /professional/courses/general /professional/societies/iee /professional/societies/acm /personal/funstuff /personal/taxes
    should in theory create your dir structure
     
  10. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    the curly brackets allow you to create multiple sub-folders in the target directory

    say you wanted to create

    parent -> child 1
    parent -> child 2

    easier but longer way

    Code:
    mkdir -p parent/child1 && parent/child2
    
    instead you would do

    Code:
    mkdir -p parent/{child1,child2}
    

    oh and your full tree, not as readable

    Code:
    mkdir -p YHD/{temp,personal{/funstuff,/taxes},professional{/courses{/general,/major{/cs213,/cs475,/cs381{/notes,/labs,/programs}}},/societies{/ieee,/acm}}}
    
     
  11. Swansen

    Swansen The Ninj

    Likes Received:
    0
    Trophy Points:
    36
    awesomeness, thank you
     
  12. donkey42

    donkey42 plank

    Likes Received:
    9
    Trophy Points:
    38
    i second that
     
  13. Fred

    Fred Moderator

    Likes Received:
    11
    Trophy Points:
    18
    My mind is blown :-O
     
  14. donkey42

    donkey42 plank

    Likes Received:
    9
    Trophy Points:
    38
    your mind is blown!, my head was a shed after that[ot]donkey is still searching for paracetamol[/ot]
     

Share This Page