Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help writing script to create sub subdirectories 1

Status
Not open for further replies.

cobble

Technical User
Aug 20, 2003
4
CA
Hi,
I really need help in writing a script to create subdirectories in subdirectories. For example, you are given a list of persons names and the types of cars they have. So after i created the directories for each of their name, how am i suppose to create subdirectories for cars which the directories will contain the types of cars each of them have. I know how to write a script to create the name directories but not a script for the cars. Pls can someone help me out as soon as possible. Thanx..a lot..
 
This is really quite easy. If you use something like mkdir ${user} to make the users subdirectories, then you only need to do mkdir ${user}/${car} for each car the user has.

Big Remember: You need to create the user directory first.

Good luck, Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Depending on your *nix, (man mkdir)
you can just attempt to create the $car subdirectories

mkdir -p $user/$car

most versions of mkdir will create the $user directory if it does not exist
 
Thanx guys for replying but the thing is i am actually needed to write a script as there are a lot of users so i can't actually create for them one by one. The problem is i am having problem writing the script.
thanx...
 
so.... you have a list of users in a file? would you like to post a few lines from that file and explain a bit more? Mike
______________________________________________________________________
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Sure, for instance the usere file will look something like that but it will have more details instead of only name and cars, it will also have addresses. So i am suppose to create directories for all the names using a script and THEN directories for each of them for cars, using a script too as there are still a lot of users. So any of you all can help me out?

Mike,Mercedes
Jane,BMW
Wayne,Corvette
Tommy,Audi
Kelvin,Skyline
Jack,Porsche
 
stanhubble's suggestion to use mkdir -p is the easiest way to do this. You don't have to have two loops. One will suffice. :)
 
but i can't just use mkdir because there are probably a 1000 person in the list so i need to create a subdirectory for each and everyone of them on cars and some may more cars thus the there will be more fields.
 
I'm not sure what it is that you think you can't do.

These lines, for instance, will work whether or not the directory /home/mike exists or not

mkdir -p /home/mike/bmwk100lt
mkdir -p /home/mike/316ise

Mike
______________________________________________________________________
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top