Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my scenario, I have some photos and I want to keep them seperate. At present I am doing mkdir gallery1 gallery2 gallery3 gallery4 gallery5 gallery6, this is a pain. I think we can do it easily as well. Suppose I want to make directories from gallery7 to gallery50. How would I do that?

share|improve this question
up vote 12 down vote accepted

With brace expansion.

mkdir gallery{1..50}
share|improve this answer
with a leading zero would be mkdir gallery{01..50} – rubo77 Nov 26 '13 at 11:10

While there are already fine answers, and you have already started, I'll throw mine in anyway.

I always prefer to make numerically sequenced files with leading zeros, like so:

mkdir $(printf "gallery%02d\n" {1..50})

This will give you directories gallery01 through gallery50. This helps to keep them nicely aligned and in the correct order when sorting.

share|improve this answer
In newer version of bash you can do mkdir gallery{01..50} to achieve the same result. – otokan Dec 18 '12 at 13:29
@otokan, wow, thanks! tested in bash 4.2.39(1) in fedora 18, it works! – LiuYan 刘研 Dec 18 '12 at 14:33

As the already mentioned brace expansion isn't supported by all shells you can also use seq from the coreutils instead:

for i in $(seq -w 1 50)
    mkdir "gallery$i"

Option -w is for equal width, i.e. creating gallery01, gallery02 etc.

share|improve this answer
No need for the loop: seq -f 'mkdir gallery%02g' 50 | sh. – manatwork Dec 18 '12 at 14:37

You can use brace expansion in a bash script. The following creates the directories gallery7 to gallery50 in the current directory:

for i in {5..70}
   mkdir "gallery$i"
share|improve this answer
You are right, but its cumbersome to create a script for tasks like this. :) Specially if shorter solutions already exists. – Santosh Kumar Jan 4 '13 at 15:12

Try first, what it will resolve in with:

seq -f 'mkdir gallery%g' 50

before you pipe the output to the shell with:

seq -f 'mkdir gallery%g' 50 | sh

This creates folders with a leading zero:

seq -f 'mkdir gallery%02g' 50 | sh
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.