Move folder structure across multiple directories [duplicate]

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











up vote
4
down vote

favorite













This question already has an answer here:



  • copy and rename files 2 directory up

    4 answers



I am trying to move one a bunch of files at once, one directory up.



This is what I tried, but did not work:




mv ./*/__test__/index.js ./*/data.js




.
├── alpha
│ ├── __test__
│ │ └── index.js
│ ├── index.js
│ └── test.js
└── beta
├── __test__
│ └── index.js
├── index.js
└── test.js


To this:



.
├── alpha
│ ├── data.js
│ ├── index.js
│ └── test.js
└── beta
├── data.js
├── index.js
└── test.js


How can I do this in unix?







share|improve this question












marked as duplicate by αғsнιη, DopeGhoti, Gilles files
Users with the  files badge can single-handedly close files questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 24 at 20:07


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    4
    down vote

    favorite













    This question already has an answer here:



    • copy and rename files 2 directory up

      4 answers



    I am trying to move one a bunch of files at once, one directory up.



    This is what I tried, but did not work:




    mv ./*/__test__/index.js ./*/data.js




    .
    ├── alpha
    │ ├── __test__
    │ │ └── index.js
    │ ├── index.js
    │ └── test.js
    └── beta
    ├── __test__
    │ └── index.js
    ├── index.js
    └── test.js


    To this:



    .
    ├── alpha
    │ ├── data.js
    │ ├── index.js
    │ └── test.js
    └── beta
    ├── data.js
    ├── index.js
    └── test.js


    How can I do this in unix?







    share|improve this question












    marked as duplicate by αғsнιη, DopeGhoti, Gilles files
    Users with the  files badge can single-handedly close files questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Mar 24 at 20:07


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite












      This question already has an answer here:



      • copy and rename files 2 directory up

        4 answers



      I am trying to move one a bunch of files at once, one directory up.



      This is what I tried, but did not work:




      mv ./*/__test__/index.js ./*/data.js




      .
      ├── alpha
      │ ├── __test__
      │ │ └── index.js
      │ ├── index.js
      │ └── test.js
      └── beta
      ├── __test__
      │ └── index.js
      ├── index.js
      └── test.js


      To this:



      .
      ├── alpha
      │ ├── data.js
      │ ├── index.js
      │ └── test.js
      └── beta
      ├── data.js
      ├── index.js
      └── test.js


      How can I do this in unix?







      share|improve this question













      This question already has an answer here:



      • copy and rename files 2 directory up

        4 answers



      I am trying to move one a bunch of files at once, one directory up.



      This is what I tried, but did not work:




      mv ./*/__test__/index.js ./*/data.js




      .
      ├── alpha
      │ ├── __test__
      │ │ └── index.js
      │ ├── index.js
      │ └── test.js
      └── beta
      ├── __test__
      │ └── index.js
      ├── index.js
      └── test.js


      To this:



      .
      ├── alpha
      │ ├── data.js
      │ ├── index.js
      │ └── test.js
      └── beta
      ├── data.js
      ├── index.js
      └── test.js


      How can I do this in unix?





      This question already has an answer here:



      • copy and rename files 2 directory up

        4 answers









      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 19:21









      ThomasReggi

      1957




      1957




      marked as duplicate by αғsнιη, DopeGhoti, Gilles files
      Users with the  files badge can single-handedly close files questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 24 at 20:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by αғsнιη, DopeGhoti, Gilles files
      Users with the  files badge can single-handedly close files questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 24 at 20:07


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          4
          down vote













          You can't use wildcards in the target argument. So at least some scripting is required:



          for d in *; do
          if [[ -d "$d" ]]; then
          pushd "$d"
          mv __test__/index.js ./data.js
          popd
          fi
          done





          share|improve this answer






















          • Look more closely. He wants to rename, not just move.
            – Wildcard
            Mar 23 at 19:33










          • @Wildcard Yeah, figured that out in the meantime :-)
            – nohillside
            Mar 23 at 19:35

















          up vote
          2
          down vote













          Here is a example that will move the files.



          for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done


          I have tested this, it does perform the move as expected.






          share|improve this answer





























            up vote
            2
            down vote













            find . -path '*/__test__/*' -type f -name "index.js" 
            -execdir echo mv -vt ../data.js ;


            Remove echo which is for dry-run to run mv command on files.






            share|improve this answer



























              up vote
              1
              down vote













              I forgot about gnu parallel!



              ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"





              share|improve this answer




















              • Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                – Ole Tange
                Mar 27 at 17:06

















              up vote
              1
              down vote













              Remove echos for the real changing.



              for i in */__test__/index.js; do
              echo mv -v "$i" "$i%%/*/data.js"
              echo rm -vr "$i%/*"
              done


              Before



              .
              ├── alpha
              │   ├── index.js
              │   ├── __test__
              │   │   └── index.js
              │   └── test.js
              └── beta
              ├── index.js
              ├── __test__
              │   └── index.js
              └── test.js


              After



              .
              ├── alpha
              │   ├── data.js
              │   ├── index.js
              │   └── test.js
              └── beta
              ├── data.js
              ├── index.js
              └── test.js





              share|improve this answer



























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                4
                down vote













                You can't use wildcards in the target argument. So at least some scripting is required:



                for d in *; do
                if [[ -d "$d" ]]; then
                pushd "$d"
                mv __test__/index.js ./data.js
                popd
                fi
                done





                share|improve this answer






















                • Look more closely. He wants to rename, not just move.
                  – Wildcard
                  Mar 23 at 19:33










                • @Wildcard Yeah, figured that out in the meantime :-)
                  – nohillside
                  Mar 23 at 19:35














                up vote
                4
                down vote













                You can't use wildcards in the target argument. So at least some scripting is required:



                for d in *; do
                if [[ -d "$d" ]]; then
                pushd "$d"
                mv __test__/index.js ./data.js
                popd
                fi
                done





                share|improve this answer






















                • Look more closely. He wants to rename, not just move.
                  – Wildcard
                  Mar 23 at 19:33










                • @Wildcard Yeah, figured that out in the meantime :-)
                  – nohillside
                  Mar 23 at 19:35












                up vote
                4
                down vote










                up vote
                4
                down vote









                You can't use wildcards in the target argument. So at least some scripting is required:



                for d in *; do
                if [[ -d "$d" ]]; then
                pushd "$d"
                mv __test__/index.js ./data.js
                popd
                fi
                done





                share|improve this answer














                You can't use wildcards in the target argument. So at least some scripting is required:



                for d in *; do
                if [[ -d "$d" ]]; then
                pushd "$d"
                mv __test__/index.js ./data.js
                popd
                fi
                done






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 23 at 19:33

























                answered Mar 23 at 19:32









                nohillside

                1,868616




                1,868616











                • Look more closely. He wants to rename, not just move.
                  – Wildcard
                  Mar 23 at 19:33










                • @Wildcard Yeah, figured that out in the meantime :-)
                  – nohillside
                  Mar 23 at 19:35
















                • Look more closely. He wants to rename, not just move.
                  – Wildcard
                  Mar 23 at 19:33










                • @Wildcard Yeah, figured that out in the meantime :-)
                  – nohillside
                  Mar 23 at 19:35















                Look more closely. He wants to rename, not just move.
                – Wildcard
                Mar 23 at 19:33




                Look more closely. He wants to rename, not just move.
                – Wildcard
                Mar 23 at 19:33












                @Wildcard Yeah, figured that out in the meantime :-)
                – nohillside
                Mar 23 at 19:35




                @Wildcard Yeah, figured that out in the meantime :-)
                – nohillside
                Mar 23 at 19:35












                up vote
                2
                down vote













                Here is a example that will move the files.



                for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done


                I have tested this, it does perform the move as expected.






                share|improve this answer


























                  up vote
                  2
                  down vote













                  Here is a example that will move the files.



                  for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done


                  I have tested this, it does perform the move as expected.






                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    Here is a example that will move the files.



                    for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done


                    I have tested this, it does perform the move as expected.






                    share|improve this answer














                    Here is a example that will move the files.



                    for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done


                    I have tested this, it does perform the move as expected.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 23 at 19:44

























                    answered Mar 23 at 19:35









                    thebtm

                    645411




                    645411




















                        up vote
                        2
                        down vote













                        find . -path '*/__test__/*' -type f -name "index.js" 
                        -execdir echo mv -vt ../data.js ;


                        Remove echo which is for dry-run to run mv command on files.






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          find . -path '*/__test__/*' -type f -name "index.js" 
                          -execdir echo mv -vt ../data.js ;


                          Remove echo which is for dry-run to run mv command on files.






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            find . -path '*/__test__/*' -type f -name "index.js" 
                            -execdir echo mv -vt ../data.js ;


                            Remove echo which is for dry-run to run mv command on files.






                            share|improve this answer












                            find . -path '*/__test__/*' -type f -name "index.js" 
                            -execdir echo mv -vt ../data.js ;


                            Remove echo which is for dry-run to run mv command on files.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 23 at 20:18









                            αғsнιη

                            14.8k82462




                            14.8k82462




















                                up vote
                                1
                                down vote













                                I forgot about gnu parallel!



                                ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"





                                share|improve this answer




















                                • Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                                  – Ole Tange
                                  Mar 27 at 17:06














                                up vote
                                1
                                down vote













                                I forgot about gnu parallel!



                                ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"





                                share|improve this answer




















                                • Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                                  – Ole Tange
                                  Mar 27 at 17:06












                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                I forgot about gnu parallel!



                                ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"





                                share|improve this answer












                                I forgot about gnu parallel!



                                ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 23 at 19:38









                                ThomasReggi

                                1957




                                1957











                                • Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                                  – Ole Tange
                                  Mar 27 at 17:06
















                                • Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                                  – Ole Tange
                                  Mar 27 at 17:06















                                Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                                – Ole Tange
                                Mar 27 at 17:06




                                Or just: parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
                                – Ole Tange
                                Mar 27 at 17:06










                                up vote
                                1
                                down vote













                                Remove echos for the real changing.



                                for i in */__test__/index.js; do
                                echo mv -v "$i" "$i%%/*/data.js"
                                echo rm -vr "$i%/*"
                                done


                                Before



                                .
                                ├── alpha
                                │   ├── index.js
                                │   ├── __test__
                                │   │   └── index.js
                                │   └── test.js
                                └── beta
                                ├── index.js
                                ├── __test__
                                │   └── index.js
                                └── test.js


                                After



                                .
                                ├── alpha
                                │   ├── data.js
                                │   ├── index.js
                                │   └── test.js
                                └── beta
                                ├── data.js
                                ├── index.js
                                └── test.js





                                share|improve this answer
























                                  up vote
                                  1
                                  down vote













                                  Remove echos for the real changing.



                                  for i in */__test__/index.js; do
                                  echo mv -v "$i" "$i%%/*/data.js"
                                  echo rm -vr "$i%/*"
                                  done


                                  Before



                                  .
                                  ├── alpha
                                  │   ├── index.js
                                  │   ├── __test__
                                  │   │   └── index.js
                                  │   └── test.js
                                  └── beta
                                  ├── index.js
                                  ├── __test__
                                  │   └── index.js
                                  └── test.js


                                  After



                                  .
                                  ├── alpha
                                  │   ├── data.js
                                  │   ├── index.js
                                  │   └── test.js
                                  └── beta
                                  ├── data.js
                                  ├── index.js
                                  └── test.js





                                  share|improve this answer






















                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    Remove echos for the real changing.



                                    for i in */__test__/index.js; do
                                    echo mv -v "$i" "$i%%/*/data.js"
                                    echo rm -vr "$i%/*"
                                    done


                                    Before



                                    .
                                    ├── alpha
                                    │   ├── index.js
                                    │   ├── __test__
                                    │   │   └── index.js
                                    │   └── test.js
                                    └── beta
                                    ├── index.js
                                    ├── __test__
                                    │   └── index.js
                                    └── test.js


                                    After



                                    .
                                    ├── alpha
                                    │   ├── data.js
                                    │   ├── index.js
                                    │   └── test.js
                                    └── beta
                                    ├── data.js
                                    ├── index.js
                                    └── test.js





                                    share|improve this answer












                                    Remove echos for the real changing.



                                    for i in */__test__/index.js; do
                                    echo mv -v "$i" "$i%%/*/data.js"
                                    echo rm -vr "$i%/*"
                                    done


                                    Before



                                    .
                                    ├── alpha
                                    │   ├── index.js
                                    │   ├── __test__
                                    │   │   └── index.js
                                    │   └── test.js
                                    └── beta
                                    ├── index.js
                                    ├── __test__
                                    │   └── index.js
                                    └── test.js


                                    After



                                    .
                                    ├── alpha
                                    │   ├── data.js
                                    │   ├── index.js
                                    │   └── test.js
                                    └── beta
                                    ├── data.js
                                    ├── index.js
                                    └── test.js






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Mar 23 at 20:46









                                    MiniMax

                                    2,681718




                                    2,681718












                                        Popular posts from this blog

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

                                        Bahrain

                                        Postfix configuration issue with fips on centos 7; mailgun relay