LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-12-2004, 12:44 PM   #1
digitalgravy
Member
 
Registered: Nov 2003
Posts: 86

Rep: Reputation: 15
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.
 
Old 08-12-2004, 12:48 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

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

and so on...
 
Old 08-12-2004, 12:57 PM   #3
digitalgravy
Member
 
Registered: Nov 2003
Posts: 86

Original Poster
Rep: Reputation: 15
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
 
Old 08-12-2004, 12:59 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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}
 
Old 08-12-2004, 01:00 PM   #5
digitalgravy
Member
 
Registered: Nov 2003
Posts: 86

Original Poster
Rep: Reputation: 15
That is what I was looking for!

Thanks both of you!
 
Old 08-12-2004, 01:03 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mkdir -p ? shanenin Linux - Software 4 10-19-2011 11:41 AM
Trying to make a directory with mkdir using the date command. Altheastronut Linux - General 5 06-09-2009 12:14 PM
can I use date command with mkdir? ewto Linux - General 6 06-16-2004 08:47 AM
mkdir help... Linux~Powered Linux - Software 2 06-13-2004 11:27 AM
mkdir help ITJedi Linux - Software 1 05-14-2004 05:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration