How to make dirs with for?

Friends, I want to create 500 directories through a for loop
which starts from 1 to 500 and their common last name is _200
like this
1_200, 2_200, 3_200 to 500_200
Can anyone help with this?

for i in {1_200…500_200}
do
mkdir $i
done
Not working

#!/bin/bash

for ((i = 1; i <= 500; i++)); do
    mkdir "${i}_200"
done
5 Likes

Is this your homework-assignment? :rofl:

3 Likes

Just in case it is your homework and you’re not allowed to use bashisms, in Bourne-shell it’s like this:

#!/bin/sh

for i in `seq 1 500`; do
    mkdir "${i}_200"
done

I don’t like it, because seq is bloat.
:frog:

4 Likes

Thank you very much, I was able to do my homework with your help
The speed of the first script was very fast

2 Likes

Naughty, naughty… therefore no :lollipop: today! :wink:

1 Like

Sounds like you now need to develop a for loop to remove said directories. Unless of course, it is the school’s computer.

Pudge

1 Like

Unless in the same directory you have some other empty directories that you want to keep,

rmdir *

will get rid of them all.

1 Like

You should tell you teacher that for loop is waste of keystrokes when you can just simply write mkdir {1..500}_200 or as I would prefer with the leading zeroes mkdir {001..500}_200.

3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.