Making 99 folders 99 folders deep | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Making 99 folders 99 folders deep

Shell Programming and Scripting


Tags
help with script, script, unix

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-25-2011
YukonAppleGeek YukonAppleGeek is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 30 June 2011, 2:54 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and over.

Here is code any suggestions:

Code:
#!/bin/bash
for num in {1..99}; do
    mkdir $num
    cd $num
    for num2 in {1..99}; do
	mkdir $num2
    done
    cd ..
done

Code for 3 folder levels

Code:
#!/bin/bash
mdir=$(pwd)
for num in {1..99}; do
    mkdir $num
    cd $num
    for num2 in {1..99}; do
	mkdir $num2
        cd $num2
        for num3 in {1..99}; do
	    mkdir $num3
        done
        cd ..
    done
    cd $mdir
done

Make 9 folders 4 deep (found at: *new so cant post url but google "10000 folders applescript" and it is the first link )

Code:
#!/bin/bash
mkdir 0
mkdir 0/0
mkdir 0/0/0
mkdir 0/0/0/0

for a in 1 2 3 4 5 6 7 8 9
do
for b in 1 2 3 4 5 6 7 8 9
do
for c in 1 2 3 4 5 6 7 8 9
do
for d in 1 2 3 4 5 6 7 8 9
do
cp -R 0/0/0/0/ 0/0/0/$d
done
cp -R 0/0/0/ 0/0/$c
done
cp -R 0/0/ 0/$b
done
cp -R 0/ $a
done
exit 0

EDIT: After making all folders have 3 levels it took 23 min so maybe not 99 deep configurable deepness if posable?
Sponsored Links
    #2  
Old 04-25-2011
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by YukonAppleGeek View Post
EDIT: After making all folders have 3 levels it took 23 min so maybe not 99 deep configurable deepness if posable?
That's a very good call. I'm not sure the universe is up to creating that many directories. 99 levels of 99 directories in 99 directories is a LOT of directories: 99^99 = 3.69729638 10^197

Allowing for the creation of one directory per nanosecond (unrealistically swift, 99^3 in 23 minutes is nearly 1.5 milliseconds) and suspending all other physical limitations, it would take:
99^99 * 10^-9 / 60 / 60 / 24 / 365 = 1.17240499 10^181 years

Many, many, many orders of magnitude beyond current estimates of the universe's age.

As to your original problem, a recursive shell function would probably be the simplest approach.

Regards and welcome to the forum,
Alister

Last edited by alister; 04-25-2011 at 11:08 PM..
Sponsored Links
    #3  
Old 04-25-2011
YukonAppleGeek YukonAppleGeek is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 30 June 2011, 2:54 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Tried

I tried doing a loop but when ever i do it does not work, it never changes the directory and then errors up.
    #4  
Old 04-26-2011
ahamed101's Avatar
ahamed101 ahamed101 is offline Forum Advisor  
root is god!!!
 
Join Date: Sep 2008
Last Activity: 15 May 2014, 2:54 PM EDT
Location: San Jose, CA
Posts: 1,906
Thanks: 54
Thanked 485 Times in 478 Posts
To be very frank, I didnt get the issue here. You created 99 folders with each folder having 99 subfolders, got that part. Now whats troubling you?
I also didn't understand the term "99 folders 99 deep" - please explain.

regards,
Ahamed
Sponsored Links
    #5  
Old 04-26-2011
YukonAppleGeek YukonAppleGeek is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 30 June 2011, 2:54 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Easer Way

I am trying to make 5 sub folders with out having to copy/paste/reformat the code. I know it is posable but i am wondering if there is a easer way of do that, i am also some what new to unix shell scripting. (I also will probably not do 99 folders more like 20-50)
Sponsored Links
    #6  
Old 04-26-2011
alister alister is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
Quote:
Originally Posted by YukonAppleGeek View Post
I am trying to make 5 sub folders with out having to copy/paste/reformat the code. I know it is posable but i am wondering if there is a easer way of do that, i am also some what new to unix shell scripting. (I also will probably not do 99 folders more like 20-50)
If your intention is to implement the algorithm in your original post, you really need to come to terms with the numbers you'd be dealing with. Based on how far you got in 23 minutes, and generously slashing the time per directory from 1.5 milliseconds to 1 millisecond flat, the following is approximately how long it would take to create n levels of n directories in each directory:


Code:
20:  3 trillion millenia
15:  14,000 millenia
10:  4 months
 9:  4.5 days
 8:  4.5 hours
 7:  14 minutes
 6:  47 seconds
 5:  3 seconds

It blows up quickly, so you'll probably want to keep it small. If you don't mind saying, why are you doing this? I'm curious.

Regards,
Alister

The arithmetic:
((((((20^20) * .001) / 60) / 60) / 24) / 365) / 1 000 = 3.32501268 10^12
((((((15^15) * .001) / 60) / 60) / 24) / 365) / 1 000 = 13,885.5242
(((((10^10) * .001) / 60) / 60) / 24) / 30 = 3.85802469
((((9^9) * .001) / 60) / 60) / 24 = 4.48403344
(((8^8) * .001) / 60) / 60 = 4.66033778
((7^7) * .001) / 60 = 13.7257167
(6^6) * .001 = 46.65600
(5^5) * .001 = 3.12500
Sponsored Links
    #7  
Old 04-26-2011
YukonAppleGeek YukonAppleGeek is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 30 June 2011, 2:54 PM EDT
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
I am just wondering if there is any way of loop the mkdir code instead of typing it over and over and over again. I am trying to learn a little about how to write unix shell scripts and how it works. *It is a lot more powerful then thought.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mv hidden folders ruben.rodrigues Shell Programming and Scripting 2 11-12-2009 08:00 AM
FTP folders from CD to AIX Box chandancsc AIX 2 08-25-2009 11:45 AM
Copying Folders without some folders... ;-) chimpu UNIX for Dummies Questions & Answers 5 04-26-2004 12:25 PM
Backing up Folders without some folders...;) chimpu Shell Programming and Scripting 1 04-26-2004 10:02 AM



All times are GMT -4. The time now is 01:31 PM.