LinuxQuestions.org
Visit Jeremy's Blog.
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 01-09-2013, 10:27 AM   #1
Sanderson
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Rep: Reputation: Disabled
Basic terminal help, about creating directories


I have a txt file with a list of names in. e.g. Work Home Doc etc

And i was wondering how to create a directory for each name in the list without typing out every name again?
 
Old 01-09-2013, 10:29 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Assuming your file is formatted as:
Code:
Work
Home
Doc
Then this would do it
Code:
while read line; do mkdir -p "$line"; done < file







If instead your fields are separated by spaces, eg:
Code:
Work Home Doc
then you could do:
Code:
for dir in $(cat file); do mkdir -p $dir; done
but you would need to make sure that none of your directories have a space in the name, or the loop will treat them as separate names.

Last edited by suicidaleggroll; 01-09-2013 at 10:32 AM.
 
Old 01-09-2013, 10:35 AM   #3
Sanderson
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks ill try this
 
Old 01-09-2013, 12:58 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or simply
Code:
mkdir $(<file)
 
  


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 directories and moving into them atjurhs Linux - Newbie 8 09-12-2012 09:34 PM
Creating multiple directories atheist Linux - Newbie 6 02-20-2009 04:32 AM
creating directories and permissions ingen Linux From Scratch 1 11-06-2008 12:38 AM
creating sub-sub directories dominant Linux - Newbie 13 07-23-2004 05:16 PM
got stuck while creating directories chupacabra Linux From Scratch 3 11-21-2002 07:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:28 AM.

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
Open Source Consulting | Domain Registration