How do I make multiple folders in a single location using relative path to the location?

prasanthv picture prasanthv · Jan 31, 2011 · Viewed 71.2k times · Source

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.

Answer

Dennis Williamson picture Dennis Williamson · Jan 31, 2011

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}