?
Solved

Directory creation

Posted on 2005-05-10
4
Medium Priority
?
283 Views
Last Modified: 2010-04-20
I want to create 225 directories, all of directory name is in file "name",
This is an example of "name"
The Imperial Samui Hotel
The Island Resort & Spa
The Jungle Club
The Lodge
The Oriental Samui Resort
The Princess Village
The Tongsai Bay

How can I create directories form files "name".
0
Comment
Question by:teera
  • 2
4 Comments
 
LVL 88

Assisted Solution

by:rindi
rindi earned 300 total points
ID: 13966542
Edit the file and add the following entries:

mkdir "The Imperial Samui Hotel"
mkdir "The Island Resort & Spa"
mkdir "The Jungle Club"
mkdir "The Lodge"
mkdir "The Oriental Samui Resort"
mkdir "The Princess Village"
mkdir "The Tongsai Bay"

Then change the file to be executable and rename it to name.sh

then run ./name.sh and the folders should be created in that folder where you are running the file from.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13966567
Hi teera,

for i in `cat name`
do
      mkdir "$i"
done

Having directory names with spaces is often a problem. It might be a good idea to replace the spaces with an _. If you intend to do that, this one liner will do it for you
sed 's/ /_/g' names

Cheers!
sunnycoder
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 1100 total points
ID: 13966585
`cat name` may give problems due to spaces, I guess this will be more apt

cat name | while read i
instead of - for i in `cat name`

You can also automate rindi's suggestion

sed -e 's/^/mkdir "/'  -e 's/$/"/` name > name.sh
0
 
LVL 2

Assisted Solution

by:sekargopi
sekargopi earned 400 total points
ID: 13985719

cd to-directory-where-needs-to-be-cread
while read dir
do
   mkdir ¨dir¨
done < /path/to/name

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question