Loop to create subdirectories in multiple directories

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I want to create subdirectories into each of directories below. I used the following loop:



#! bash

/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir

done


but it creates one subdirectory at the same level of directories:



$ ls 
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir


I want to get them in this way



$ ls /m3z 
/log /lib /txt

$ ls /m3t
/log /lib /txt
.
.
.

$ ls /n dir
/log /lib /txt


Help?










share|improve this question



















  • 1




    Possible duplicate of Issue with Bash Script creating Directories from Arrays
    – kemotep
    Aug 13 at 15:55














up vote
0
down vote

favorite












I want to create subdirectories into each of directories below. I used the following loop:



#! bash

/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir

done


but it creates one subdirectory at the same level of directories:



$ ls 
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir


I want to get them in this way



$ ls /m3z 
/log /lib /txt

$ ls /m3t
/log /lib /txt
.
.
.

$ ls /n dir
/log /lib /txt


Help?










share|improve this question



















  • 1




    Possible duplicate of Issue with Bash Script creating Directories from Arrays
    – kemotep
    Aug 13 at 15:55












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to create subdirectories into each of directories below. I used the following loop:



#! bash

/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir

done


but it creates one subdirectory at the same level of directories:



$ ls 
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir


I want to get them in this way



$ ls /m3z 
/log /lib /txt

$ ls /m3t
/log /lib /txt
.
.
.

$ ls /n dir
/log /lib /txt


Help?










share|improve this question















I want to create subdirectories into each of directories below. I used the following loop:



#! bash

/# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n dir
do
echo "Processing $d"
mkdir log #subdir
mkdir lib #subdir
mkdir txt #subdir

done


but it creates one subdirectory at the same level of directories:



$ ls 
m3z m3t m3t2 m3g m3g2 m3g3 log lib txt .... n dir


I want to get them in this way



$ ls /m3z 
/log /lib /txt

$ ls /m3t
/log /lib /txt
.
.
.

$ ls /n dir
/log /lib /txt


Help?







bash loop-device mkdir






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 13 at 19:48









slm♦

238k65492662




238k65492662










asked Aug 13 at 14:39









Djegdjiga AMAZOUZ

6




6







  • 1




    Possible duplicate of Issue with Bash Script creating Directories from Arrays
    – kemotep
    Aug 13 at 15:55












  • 1




    Possible duplicate of Issue with Bash Script creating Directories from Arrays
    – kemotep
    Aug 13 at 15:55







1




1




Possible duplicate of Issue with Bash Script creating Directories from Arrays
– kemotep
Aug 13 at 15:55




Possible duplicate of Issue with Bash Script creating Directories from Arrays
– kemotep
Aug 13 at 15:55










1 Answer
1






active

oldest

votes

















up vote
5
down vote













Assuming the m3* directories exist,



for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log,lib,txt
done


or, with brace expansion on the list of directories,



mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt


or even,



mkdir m3z,t,t2,g,g2,g3/log,lib,txt


or, without the brace expansion,



for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done


or, if the directories that you loop over are not already existing.



for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
done


or, if the directories that you loop over already exist and all match the pattern m3*/,



for dir in m3*/; do
mkdir "$dir"/log "$dir"/lib "$dir"/txt
done


The main thing is to specify that you'd like to create the directories as subdirectories of $dir, the directory name that you currently process in your loop.






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462315%2floop-to-create-subdirectories-in-multiple-directories%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    Assuming the m3* directories exist,



    for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
    mkdir "$dir"/log,lib,txt
    done


    or, with brace expansion on the list of directories,



    mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt


    or even,



    mkdir m3z,t,t2,g,g2,g3/log,lib,txt


    or, without the brace expansion,



    for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
    mkdir "$dir"/log "$dir"/lib "$dir"/txt
    done


    or, if the directories that you loop over are not already existing.



    for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
    mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
    done


    or, if the directories that you loop over already exist and all match the pattern m3*/,



    for dir in m3*/; do
    mkdir "$dir"/log "$dir"/lib "$dir"/txt
    done


    The main thing is to specify that you'd like to create the directories as subdirectories of $dir, the directory name that you currently process in your loop.






    share|improve this answer


























      up vote
      5
      down vote













      Assuming the m3* directories exist,



      for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
      mkdir "$dir"/log,lib,txt
      done


      or, with brace expansion on the list of directories,



      mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt


      or even,



      mkdir m3z,t,t2,g,g2,g3/log,lib,txt


      or, without the brace expansion,



      for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
      mkdir "$dir"/log "$dir"/lib "$dir"/txt
      done


      or, if the directories that you loop over are not already existing.



      for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
      mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
      done


      or, if the directories that you loop over already exist and all match the pattern m3*/,



      for dir in m3*/; do
      mkdir "$dir"/log "$dir"/lib "$dir"/txt
      done


      The main thing is to specify that you'd like to create the directories as subdirectories of $dir, the directory name that you currently process in your loop.






      share|improve this answer
























        up vote
        5
        down vote










        up vote
        5
        down vote









        Assuming the m3* directories exist,



        for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
        mkdir "$dir"/log,lib,txt
        done


        or, with brace expansion on the list of directories,



        mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt


        or even,



        mkdir m3z,t,t2,g,g2,g3/log,lib,txt


        or, without the brace expansion,



        for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
        mkdir "$dir"/log "$dir"/lib "$dir"/txt
        done


        or, if the directories that you loop over are not already existing.



        for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
        mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
        done


        or, if the directories that you loop over already exist and all match the pattern m3*/,



        for dir in m3*/; do
        mkdir "$dir"/log "$dir"/lib "$dir"/txt
        done


        The main thing is to specify that you'd like to create the directories as subdirectories of $dir, the directory name that you currently process in your loop.






        share|improve this answer














        Assuming the m3* directories exist,



        for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
        mkdir "$dir"/log,lib,txt
        done


        or, with brace expansion on the list of directories,



        mkdir m3z,m3t,m3t2,m3g,m3g2,m3g3/log,lib,txt


        or even,



        mkdir m3z,t,t2,g,g2,g3/log,lib,txt


        or, without the brace expansion,



        for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
        mkdir "$dir"/log "$dir"/lib "$dir"/txt
        done


        or, if the directories that you loop over are not already existing.



        for dir in m3z m3t m3t2 m3g m3g2 m3g3; do
        mkdir -p "$dir"/log "$dir"/lib "$dir"/txt
        done


        or, if the directories that you loop over already exist and all match the pattern m3*/,



        for dir in m3*/; do
        mkdir "$dir"/log "$dir"/lib "$dir"/txt
        done


        The main thing is to specify that you'd like to create the directories as subdirectories of $dir, the directory name that you currently process in your loop.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Aug 13 at 14:51

























        answered Aug 13 at 14:45









        Kusalananda

        106k14209327




        106k14209327



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462315%2floop-to-create-subdirectories-in-multiple-directories%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?