Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I want to create ten folders named foo1java, foo2c, foo3python, etc.

I tried this but it creates too many directories:

mkdir foo{1..3}{java,c,python}

foo1c/     foo1python/  foo2java/    foo3c/     foo3python/
foo1java/  foo2c/       foo2python/  foo3java/

I just want map the numbers to the languages: 1 to java, 2 to c, 3 to python, etc.

How would I go about doing this?

share|improve this question
up vote 5 down vote accepted
i=1; for j in java c python; do mkdir foo${i}${j}; i=$((i+1)); done

gives directories


To add more languages, just keep filling the word list after python with space-separated entities. The integer counter will keep up.

Addition: "Bashier" (but not better, so I would prefer the above solution, since it is more portable (even though it probably doesn't matter in this case)):

list=(java c python); i=1; while [ $i -lt ${#list} ]; do mkdir foo${i}${list[i-1]}; let i++; done

Just fill the array list with more entries as before.

share|improve this answer
I hope to see short command line to solve this problem, if there is no any better answers, I would mark this answer. Thanks – HVNSweeting Apr 7 '12 at 13:14

It's a static mapping, so factor it out.

mkdir foo{1java,2c,3python}
share|improve this answer

Another possible way (bash)

  arr=(java c python); for((i = 1; i <= ${#arr[@]}; i++)); do mkdir foo${i}${arr[i-1]} ; done
share|improve this answer

No looping...

paste <( printf '%s\n' foo{1..3} ) \
      <( printf '%s\n' java c python ) |tr -d '\t' | xargs mkdir -p
share|improve this answer

This might work for you:

parallel --xapply mkdir foo{1}{2} ::: {1..3} ::: {java,c,python}
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.