39

What I'm trying to do is create a number of folders in the "~/Labs/lab4a/" location (~/Labs/lab4a/ already exists).

Say I want folder1, folder2, folder3 all in the lab4a folder.

This isn't about making nested folders all at one go using the mkdir -p command or going in to lab4a and just making multiple folders at one go. I'm wondering is there a faster way using mkdir to create multiple folders in the same location using relative path.

i.e prompt~/: mkdir Labs/lab4a/folder1 folder2 folder3 To create all those folders in lab4a at once.

1
  • 2
    voting to close - this should be migrated to superuser, right? Commented Sep 12, 2014 at 13:34

4 Answers 4

60

In Bash and other shells that support it, you can do

mkdir ~/Labs/lab4a/folder{1..3} 

or

mkdir ~/Labs/lab4a/folder{1,2,3} 

Other options:

mkdir $(seq -f "$HOME/Labs/lab4a/folder%03g" 3) mkdir $(printf "$HOME/Labs/lab4a/folder%03g " {0..3}) 

Which will give you leading zeros which make sorting easier.

This will do the same thing in Bash 4:

mkdir ~/Labs/lab4a/folder{001..3} 
Sign up to request clarification or add additional context in comments.

Comments

45

Use shell expansion :

mkdir Labs/lab4a/{folder1,myfolder,foofolder} 

That such an underestimated possibility :)

my2c

Comments

2

Go to console -

cd ...

mkdir {8...30}

Create multiple folders linux

Comments

2

I would use mkdir with the -p option as it creates intermediate directories as required :

mkdir -p ~/var/www/html/site1/{site2/{html,logs,images},site{3..6},site7} 

this creates this output so in your case,

mkdir -p ~/Labs/lab4a/folder{1..3} 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.