Merge one folder onto another but keep diff (non-existing) files

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








up vote
1
down vote

favorite












Suppose I have the following structure:



Folder-A
File-1
File-2
File-4
Folder-A-1
File-5
File-6
Folder-A-2
File-7

Folder-B
File-1
File-2
File-3
Folder-A-1
File-5


I want to copy Folder-A onto / on top of Folder-B so that, logically, the result is this:



Folder-B
File-1 *
File-2 *
File-3
File-4 +
Folder-A-1
File-5 *
File-6 +
Folder-A-2 +
File-7 +


Where * is an overwrite and + is an addition.



In other words, recursively, if the file (or folder) exists in the same path, overwrite it, and if it's new, add it.



How would I do this?







share|improve this question
























    up vote
    1
    down vote

    favorite












    Suppose I have the following structure:



    Folder-A
    File-1
    File-2
    File-4
    Folder-A-1
    File-5
    File-6
    Folder-A-2
    File-7

    Folder-B
    File-1
    File-2
    File-3
    Folder-A-1
    File-5


    I want to copy Folder-A onto / on top of Folder-B so that, logically, the result is this:



    Folder-B
    File-1 *
    File-2 *
    File-3
    File-4 +
    Folder-A-1
    File-5 *
    File-6 +
    Folder-A-2 +
    File-7 +


    Where * is an overwrite and + is an addition.



    In other words, recursively, if the file (or folder) exists in the same path, overwrite it, and if it's new, add it.



    How would I do this?







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Suppose I have the following structure:



      Folder-A
      File-1
      File-2
      File-4
      Folder-A-1
      File-5
      File-6
      Folder-A-2
      File-7

      Folder-B
      File-1
      File-2
      File-3
      Folder-A-1
      File-5


      I want to copy Folder-A onto / on top of Folder-B so that, logically, the result is this:



      Folder-B
      File-1 *
      File-2 *
      File-3
      File-4 +
      Folder-A-1
      File-5 *
      File-6 +
      Folder-A-2 +
      File-7 +


      Where * is an overwrite and + is an addition.



      In other words, recursively, if the file (or folder) exists in the same path, overwrite it, and if it's new, add it.



      How would I do this?







      share|improve this question












      Suppose I have the following structure:



      Folder-A
      File-1
      File-2
      File-4
      Folder-A-1
      File-5
      File-6
      Folder-A-2
      File-7

      Folder-B
      File-1
      File-2
      File-3
      Folder-A-1
      File-5


      I want to copy Folder-A onto / on top of Folder-B so that, logically, the result is this:



      Folder-B
      File-1 *
      File-2 *
      File-3
      File-4 +
      Folder-A-1
      File-5 *
      File-6 +
      Folder-A-2 +
      File-7 +


      Where * is an overwrite and + is an addition.



      In other words, recursively, if the file (or folder) exists in the same path, overwrite it, and if it's new, add it.



      How would I do this?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 28 at 16:24









      Oliver Williams

      1337




      1337




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          That's the default behavior of cp. So all you need to do is a regular recursive cp:



          cp -r Folder-A/* Folder-B/



          To demonstrate:



          $ tree
          .
          ├── Folder-A
          │   ├── File-1
          │   ├── File-2
          │   ├── File-4
          │   ├── Folder-A-1
          │   │   ├── File-5
          │   │   └── File-6
          │   └── Folder-A-2
          │   └── File-7
          └── Folder-B
          ├── File-1
          ├── File-2
          ├── File-3
          └── Folder-A-1
          └── File-5

          $ cp -r Folder-A/* Folder-B
          $ tree
          .
          ├── Folder-A
          │   ├── File-1
          │   ├── File-2
          │   ├── File-4
          │   ├── Folder-A-1
          │   │   ├── File-5
          │   │   └── File-6
          │   └── Folder-A-2
          │   └── File-7
          └── Folder-B
          ├── File-1
          ├── File-2
          ├── File-3
          ├── File-4
          ├── Folder-A-1
          │   ├── File-5
          │   └── File-6
          └── Folder-A-2
          └── File-7





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            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: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1029305%2fmerge-one-folder-onto-another-but-keep-diff-non-existing-files%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
            1
            down vote













            That's the default behavior of cp. So all you need to do is a regular recursive cp:



            cp -r Folder-A/* Folder-B/



            To demonstrate:



            $ tree
            .
            ├── Folder-A
            │   ├── File-1
            │   ├── File-2
            │   ├── File-4
            │   ├── Folder-A-1
            │   │   ├── File-5
            │   │   └── File-6
            │   └── Folder-A-2
            │   └── File-7
            └── Folder-B
            ├── File-1
            ├── File-2
            ├── File-3
            └── Folder-A-1
            └── File-5

            $ cp -r Folder-A/* Folder-B
            $ tree
            .
            ├── Folder-A
            │   ├── File-1
            │   ├── File-2
            │   ├── File-4
            │   ├── Folder-A-1
            │   │   ├── File-5
            │   │   └── File-6
            │   └── Folder-A-2
            │   └── File-7
            └── Folder-B
            ├── File-1
            ├── File-2
            ├── File-3
            ├── File-4
            ├── Folder-A-1
            │   ├── File-5
            │   └── File-6
            └── Folder-A-2
            └── File-7





            share|improve this answer
























              up vote
              1
              down vote













              That's the default behavior of cp. So all you need to do is a regular recursive cp:



              cp -r Folder-A/* Folder-B/



              To demonstrate:



              $ tree
              .
              ├── Folder-A
              │   ├── File-1
              │   ├── File-2
              │   ├── File-4
              │   ├── Folder-A-1
              │   │   ├── File-5
              │   │   └── File-6
              │   └── Folder-A-2
              │   └── File-7
              └── Folder-B
              ├── File-1
              ├── File-2
              ├── File-3
              └── Folder-A-1
              └── File-5

              $ cp -r Folder-A/* Folder-B
              $ tree
              .
              ├── Folder-A
              │   ├── File-1
              │   ├── File-2
              │   ├── File-4
              │   ├── Folder-A-1
              │   │   ├── File-5
              │   │   └── File-6
              │   └── Folder-A-2
              │   └── File-7
              └── Folder-B
              ├── File-1
              ├── File-2
              ├── File-3
              ├── File-4
              ├── Folder-A-1
              │   ├── File-5
              │   └── File-6
              └── Folder-A-2
              └── File-7





              share|improve this answer






















                up vote
                1
                down vote










                up vote
                1
                down vote









                That's the default behavior of cp. So all you need to do is a regular recursive cp:



                cp -r Folder-A/* Folder-B/



                To demonstrate:



                $ tree
                .
                ├── Folder-A
                │   ├── File-1
                │   ├── File-2
                │   ├── File-4
                │   ├── Folder-A-1
                │   │   ├── File-5
                │   │   └── File-6
                │   └── Folder-A-2
                │   └── File-7
                └── Folder-B
                ├── File-1
                ├── File-2
                ├── File-3
                └── Folder-A-1
                └── File-5

                $ cp -r Folder-A/* Folder-B
                $ tree
                .
                ├── Folder-A
                │   ├── File-1
                │   ├── File-2
                │   ├── File-4
                │   ├── Folder-A-1
                │   │   ├── File-5
                │   │   └── File-6
                │   └── Folder-A-2
                │   └── File-7
                └── Folder-B
                ├── File-1
                ├── File-2
                ├── File-3
                ├── File-4
                ├── Folder-A-1
                │   ├── File-5
                │   └── File-6
                └── Folder-A-2
                └── File-7





                share|improve this answer












                That's the default behavior of cp. So all you need to do is a regular recursive cp:



                cp -r Folder-A/* Folder-B/



                To demonstrate:



                $ tree
                .
                ├── Folder-A
                │   ├── File-1
                │   ├── File-2
                │   ├── File-4
                │   ├── Folder-A-1
                │   │   ├── File-5
                │   │   └── File-6
                │   └── Folder-A-2
                │   └── File-7
                └── Folder-B
                ├── File-1
                ├── File-2
                ├── File-3
                └── Folder-A-1
                └── File-5

                $ cp -r Folder-A/* Folder-B
                $ tree
                .
                ├── Folder-A
                │   ├── File-1
                │   ├── File-2
                │   ├── File-4
                │   ├── Folder-A-1
                │   │   ├── File-5
                │   │   └── File-6
                │   └── Folder-A-2
                │   └── File-7
                └── Folder-B
                ├── File-1
                ├── File-2
                ├── File-3
                ├── File-4
                ├── Folder-A-1
                │   ├── File-5
                │   └── File-6
                └── Folder-A-2
                └── File-7






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 28 at 23:37









                terdon♦

                61.8k12125204




                61.8k12125204



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1029305%2fmerge-one-folder-onto-another-but-keep-diff-non-existing-files%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Which professions warranted travel in Medieval times?

                    How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

                    Trouble downloading packages list due to a “Hash sum mismatch” error