LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   mkdir command (https://www.linuxquestions.org/questions/linux-general-1/mkdir-command-216769/)

digitalgravy 08-12-2004 12:44 PM

mkdir command
 
I read the man page, but I wanted to know the proper syntax for making multiple directories and some with sub directories.

ie, a calendar setup
Calendar
>2002
>2003
>2004
->Jan
->Feb
->Mar
->Apr
->May
->June
->Jul
etc.

Thanks in advance.

david_ross 08-12-2004 12:48 PM

You just use:
mkdir -p Calander/2004/Jan Calander/2004/Feb Calander/2004/Mar

and so on...

digitalgravy 08-12-2004 12:57 PM

I saw online somewhere that there was something like this:

mkdir -p calendar{2000 2001 2002 2003}

But I cant find it. It might have been with [] or maybe {}.

Do you know about this at all?

Thanks

Dark_Helmet 08-12-2004 12:59 PM

And here's a neat little shell expansion trick (although it is kinda ugly):

mkdir -p Calendar/200{2,3,4}/{Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec}

digitalgravy 08-12-2004 01:00 PM

That is what I was looking for!

Thanks both of you!

Dark_Helmet 08-12-2004 01:03 PM

Hehehe... responded while I was typing. What happens using the curly braces is that the shell expands the text so there will be one item for each value separated by a comma. So, with your example (replacing the spaces with commas and adding a forward slash):

mkdir -p calendar/{2000,2001,2002,2003}

The shell expands that to:

mkdir -p calendar/2000 calendar/2001 calendar/2002 calendar/2003

By repeating the curly braces, you "double up" so to speak.

mkdir -p calendar/{2000,2001}/{Jan,Feb,Mar}

becomes:

mkdir -p calendar/2000/Jan calendar/2000/Feb calendar/2000/Mar calendar/2001/Jan calendar/2001/Feb calendar/2001/Mar


All times are GMT -5. The time now is 05:23 PM.