Directory creation

Posted on 2005-05-10
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".
Question by:teera
    LVL 87

    Assisted Solution

    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

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

    Expert Comment

    Hi teera,

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

    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

    LVL 45

    Accepted Solution

    `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 >
    LVL 2

    Assisted Solution


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


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
    Join Greg Farro and Ethan Banks from Packet Pushers ( and Greg Ross from Paessler ( for a discussion about smart network …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    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…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now