Unix making directory trees

I know there is the

mkdir work/homework
if your in your home directory, and there is also the
mkdir -p work/homework/ch1/ch2
But what if i want to make multiple directories in a directory?? using THIS tree for example, how would i make that?

The image you linked is a totally different type of directory tree… not the same type of directory at all. You’re talking about directories as in filesystem directories, whereas this is a database style directory ala Lightweight Directory Access Protocol - Wikipedia, the free encyclopedia

no, i was using it as an example, as if it that tree were folders, how would the command look to make that tree.

I think that you need to browse to the directory where you want to create multiple folders. For example:

cd /folder1

And then create every folder seperately.

mkdir 01
mkdir 02
mkdir 03

Actually, Swansen actually had it better already:

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?

Just out of curiosity - do you issue the

[QUOTE=Swansen]
mkdir -p work/homework/ch1/ch2
[/QUOTE]

after you already created

[QUOTE=Swansen]
mkdir work/homework
[/QUOTE]

?

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:

you can build the whole tree in one command:

I know you could do

mkdir -p parent/{child1,child2}

but had a shot in the dark with the version below, which worked perfect

mkdir -p com/pisoftware/{people{/bmarshal,/jparker},group{/dev,/sysadmin}}

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??

i havn’t tested it but we were both thinking alikecd ~/ 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/taxesshould in theory create your dir structure

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

mkdir -p parent/child1 && parent/child2

instead you would do

mkdir -p parent/{child1,child2}

oh and your full tree, not as readable

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

awesomeness, thank you

i second that

My mind is blown :open_mouth:

your mind is blown!, my head was a shed after that[ot]donkey is still searching for paracetamol[/ot]