LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 11: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, 11:29 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
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 11:32 AM.
 
Old 01-09-2013, 11:35 AM   #3
Sanderson
LQ Newbie
 
Registered: Jan 2013
Posts: 7

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

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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 10:34 PM
Creating multiple directories atheist Linux - Newbie 6 02-20-2009 05:32 AM
creating directories and permissions ingen Linux From Scratch 1 11-06-2008 01:38 AM
creating sub-sub directories dominant Linux - Newbie 13 07-23-2004 06:16 PM
got stuck while creating directories chupacabra Linux From Scratch 3 11-21-2002 08:58 PM


All times are GMT -5. The time now is 06:33 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