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
Is this your homework-assignment?
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.
Thank you very much, I was able to do my homework with your help
The speed of the first script was very fast
Naughty, naughty… therefore no today!
Sounds like you now need to develop a for loop to remove said directories. Unless of course, it is the school’s computer.
Pudge
Unless in the same directory you have some other empty directories that you want to keep,
rmdir *
will get rid of them all.
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
.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.