Hi all,

I need to create thousands of directories in a single parent directory using shell scripting code. One problem would be to generate the unique directory name for each of the 1000 iterations to create a directory every time. ie first time the directory name needs to be subdir1 and then subdir2 for the next iteration and so on.
Could anyone please help me with the script?

Thanking you,
Prashanth

Recommended Answers

All 7 Replies

ITERATIONS=1000
for i in `seq $ITERATIONS`; do mkdir /dir/subdir$i ; done

^Thanks. I also wanted to find how to that.

'seq' may not work in all environments.
Here is the code.

!#/bin/bash
for((j=1;j<=1000;j++));do
mkdir subdir_$j 2> /dev/null
done

to delete again:

!#/bin/bash
for((j=1;j<=1000;j++));do
rmdir subdir_$j  2> /dev/null
done

good point, I tend to be too Linux focused :)

Let me know in case of any problem with he script in any
environments like:

UNIX (SUN SOLARIS)
LINUX
UBUNTU and all flavours.

Hi thanks DimaYasny and all,
the script (with the seq) did work for me..

Hey Prashanth, If you got your answer then please mark this thread as solved and close it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.