LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-29-2004, 03:09 PM   #1
shelby
Member
 
Registered: Nov 2002
Location: Rio Rancho, NM
Distribution: RHEL, CentOS & Ubuntu
Posts: 90

Rep: Reputation: 15
mkdir script


I have a file that contains 100 directories I need to create. I would rather have some sort of script read the file and create each directory than typing it by hand. The file that contains the names is setup with one directory name per line. Suggestions? Thanks
 
Old 11-29-2004, 03:11 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Code:
for i in `cat filename`; do mkdir $i; done
and if these directories contain whitespace
Code:
OLDIFS=$IFS
IFS=$'\n'
for i in `cat filename`; do mkdir $i; done
IFS=$OLDIFS

Last edited by acid_kewpie; 11-29-2004 at 03:15 PM.
 
Old 11-29-2004, 03:12 PM   #3
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
'for()' is your friend

Code:
for D `cat /path/to/file`; do 
        mkdir ${D};
done;
 
Old 11-29-2004, 03:56 PM   #4
shelby
Member
 
Registered: Nov 2002
Location: Rio Rancho, NM
Distribution: RHEL, CentOS & Ubuntu
Posts: 90

Original Poster
Rep: Reputation: 15
Excellent thank you so much. I found the for command but was unsure on how to use it.
 
  


Reply



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
mkdir -p ? shanenin Linux - Software 4 10-19-2011 11:41 AM
mkdir in / with out being root Gustaf Slackware 5 10-21-2004 02:39 PM
mkdir command digitalgravy Linux - General 5 08-12-2004 01:03 PM
mkdir help... Linux~Powered Linux - Software 2 06-13-2004 11:27 AM
mkdir help ITJedi Linux - Software 1 05-14-2004 05:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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