943,704 Members | Top Members by Rank

Ad:
Jul 5th, 2009
0

need to create 1000's of directories using shell script

Expand Post »
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
Last edited by prashanth s j; Jul 5th, 2009 at 10:34 am. Reason: spelling mistake: modified first name to first time
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
prashanth s j is offline Offline
50 posts
since Dec 2008
Jul 5th, 2009
0

Re: need to create 1000's of directories using shell script

ITERATIONS=1000
for i in `seq $ITERATIONS`; do mkdir /dir/subdir$i ; done
Moderator
Featured Poster
Reputation Points: 183
Solved Threads: 89
Posting Virtuoso
DimaYasny is offline Offline
1,772 posts
since Jan 2007
Jul 11th, 2009
0

Re: need to create 1000's of directories using shell script

^Thanks. I also wanted to find how to that.
Reputation Points: 10
Solved Threads: 4
Light Poster
ThinkFree is offline Offline
26 posts
since Jul 2009
Jul 14th, 2009
0

Re: need to create 1000's of directories using shell script

'seq' may not work in all environments.
Here is the code.
Shell Scripting Syntax (Toggle Plain Text)
  1. !#/bin/bash
  2. for((j=1;j<=1000;j++));do
  3. mkdir subdir_$j 2> /dev/null
  4. done

to delete again:

Shell Scripting Syntax (Toggle Plain Text)
  1. !#/bin/bash
  2. for((j=1;j<=1000;j++));do
  3. rmdir subdir_$j 2> /dev/null
  4. done
Last edited by Dream2code; Jul 14th, 2009 at 12:59 pm.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 14th, 2009
0

Re: need to create 1000's of directories using shell script

good point, I tend to be too Linux focused
Moderator
Featured Poster
Reputation Points: 183
Solved Threads: 89
Posting Virtuoso
DimaYasny is offline Offline
1,772 posts
since Jan 2007
Jul 15th, 2009
0

Re: need to create 1000's of directories using shell script

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

UNIX (SUN SOLARIS)
LINUX
UBUNTU and all flavours.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 15th, 2009
0

Re: need to create 1000's of directories using shell script

Hi thanks DimaYasny and all,
the script (with the seq) did work for me..
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
prashanth s j is offline Offline
50 posts
since Dec 2008
Jul 16th, 2009
0

Re: need to create 1000's of directories using shell script

Hey Prashanth, If you got your answer then please mark this thread as solved and close it.
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: dead.letter issue
Next Thread in Shell Scripting Forum Timeline: Create a batch file that executes C# application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC