LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-20-2008, 12:37 AM   #1
JJV
Member
 
Registered: Aug 2003
Location: Canada
Distribution: Mandriva2005/Fedora4/Redhat 9 / mandrake 8/win2000 /win xp / Beos /
Posts: 39

Rep: Reputation: 15
Cool Creating Folders


Hi All Young and old

Got a Question for all the smart people?

Here go's

I would like to create let say 100 folders inside every folders there has to be a text file plus 1 more folder and that folder has to have a spicific
name as well . I would like to do this through a list in a text file so piping would be in folded.

Is this possible or do I have to write a bash file for all of this.


Thanks again
Yours truly
JohnnyV
 
Old 02-20-2008, 01:59 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
There is probably a convoluted regexp for this, but the script method is best, yes.
You'd step through the list, create the directory, cd into it, create the subdirectory and text file, cd up, go to next line on the list.

It helps if you choose systematic naming.
 
Old 02-20-2008, 02:19 AM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
This sounds like a homework assignment. It's your responsibility to do your homework.

What you want to do is possible using shell scripting. Two good resources to read to help you complete your assignment are: The Absolute Bash-scripting Guide and the Bash Guide for Beginners. Both can be found on the internet.
 
Old 02-20-2008, 04:42 AM   #4
JJV
Member
 
Registered: Aug 2003
Location: Canada
Distribution: Mandriva2005/Fedora4/Redhat 9 / mandrake 8/win2000 /win xp / Beos /
Posts: 39

Original Poster
Rep: Reputation: 15
Smile Creating folders

Hi and thank you

First no it is not homework.
Now what if you just want to create from a text file with a list of names inside.

Say
A B C D E F etc ... is there a command from the shell that one can use
to pipe through a text file with a list and so create the folders.

I am already working on the script for it it is just the naming of the folders that has me little stumped

But thanks for the reply

JohnnyV
 
Old 02-20-2008, 04:59 AM   #5
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Maybe something like:
for i in < list.txt
do
mkdir $i
done

Using redirect to input the names from the list of names to use (one name per line in the list). You should realize that this will work in your home directory when logged in as user. To create the directories elswhere, the script will have to run with root authority.

This would work as the outer loop to create the topmost directory, then nest an inner loop to create the inner folder and text file.

Last edited by bigrigdriver; 02-20-2008 at 05:00 AM.
 
Old 02-20-2008, 02:27 PM   #6
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
Quote:
Originally Posted by bigrigdriver View Post
Maybe something like:
for i in < list.txt
do
mkdir $i
done
Unless I miss something, that's the same as
Code:
xargs mkdir < list.txt
But if you do the for loop, you can add the rest of your task:
Code:
echo x > $i/text-file
mkdir $i/specific-name
 
Old 02-20-2008, 03:43 PM   #7
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Responses to posts often reflect the experience level of the person making the suggestion. Case in point: my contribution reflects beginner level scripting skills; Quigi's response reflects a more advanced skill level.

But both illustrate a truism in GNU/Linux: there is more that one way to get the job done.

Thanks, Quigi. My knowledge has increased thanks to your suggestion.

Or, if there is any truth in a favorite fantasy of mine: I'm really a top-notch script writer, but I tailored my response to my perceived skill level of the person who posted the problem.

Hmmm. Is he, or isn't he.

Last edited by bigrigdriver; 02-20-2008 at 03:45 PM.
 
Old 02-21-2008, 10:44 AM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by JJV View Post
I would like to create let say 100 folders inside every folders there has to be a text file plus 1 more folder and that folder has to have a spicific name as well .
  1. What relationship do the names of the parent folder, the text file, & the sub-folder have to each other?
    Examples wouldn't hurt.
  2. Do the text files have to have content, or just get created?

Quote:
Originally Posted by JJV View Post
I would like to do this through a list in a text file so piping would be in folded.
Huh?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
creating folders under opt/lampp/htdocs folder in fedora sent222 Linux - Newbie 3 01-03-2008 05:46 AM
change permissions of all folders and sub folders cad Linux - General 3 01-28-2007 11:21 AM
Fedora: Error creating folders or writing to files thecrozz Linux - Software 1 02-02-2006 08:12 AM
Samba can create new files and folders but access denied in any new folders k.king Linux - Networking 2 01-15-2006 07:14 AM
creating files/folders accessing root folder remotely NapalmBob Linux - Networking 2 09-24-2004 11:47 PM


All times are GMT -5. The time now is 05:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration