need to create 1000's of directories using shell script

Reply

Join Date: Dec 2008
Posts: 10
Reputation: prashanth s j is an unknown quantity at this point 
Solved Threads: 0
prashanth s j prashanth s j is offline Offline
Newbie Poster

need to create 1000's of directories using shell script

 
0
  #1
Jul 5th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1,763
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Solved Threads: 85
Moderator
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

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

 
0
  #2
Jul 5th, 2009
ITERATIONS=1000
for i in `seq $ITERATIONS`; do mkdir /dir/subdir$i ; done
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 24
Reputation: ThinkFree is an unknown quantity at this point 
Solved Threads: 3
ThinkFree ThinkFree is offline Offline
Newbie Poster

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

 
0
  #3
Jul 11th, 2009
^Thanks. I also wanted to find how to that.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

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

 
0
  #4
Jul 14th, 2009
'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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 1,763
Reputation: DimaYasny will become famous soon enough DimaYasny will become famous soon enough 
Solved Threads: 85
Moderator
Featured Poster
DimaYasny DimaYasny is offline Offline
Posting Virtuoso

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

 
0
  #5
Jul 14th, 2009
good point, I tend to be too Linux focused
Real stupidity always beats Artificial Intelligence. (Terry Pratchett)

BA BizMg, MCSE, DCSE, Linux+, Network+
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

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

 
0
  #6
Jul 15th, 2009
Let me know in case of any problem with he script in any
environments like:

UNIX (SUN SOLARIS)
LINUX
UBUNTU and all flavours.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 10
Reputation: prashanth s j is an unknown quantity at this point 
Solved Threads: 0
prashanth s j prashanth s j is offline Offline
Newbie Poster

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

 
0
  #7
Jul 15th, 2009
Hi thanks DimaYasny and all,
the script (with the seq) did work for me..
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 139
Reputation: Dream2code is an unknown quantity at this point 
Solved Threads: 11
Dream2code's Avatar
Dream2code Dream2code is offline Offline
Junior Poster

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

 
0
  #8
Jul 16th, 2009
Hey Prashanth, If you got your answer then please mark this thread as solved and close it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC