How do I replace a folder with its only subfolder of the same name in CLI?

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











up vote
1
down vote

favorite












Suppose that I have only the following in ~/foo:



.
..
foo


With file managers if I cut the subfolder foo and paste it into ~ it automatically replaces the contents of ~/foo with that of ~/foo/foo.



But is there a native command-line tool to do so, although I can achieve the goal with a function, too?







share|improve this question

























    up vote
    1
    down vote

    favorite












    Suppose that I have only the following in ~/foo:



    .
    ..
    foo


    With file managers if I cut the subfolder foo and paste it into ~ it automatically replaces the contents of ~/foo with that of ~/foo/foo.



    But is there a native command-line tool to do so, although I can achieve the goal with a function, too?







    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Suppose that I have only the following in ~/foo:



      .
      ..
      foo


      With file managers if I cut the subfolder foo and paste it into ~ it automatically replaces the contents of ~/foo with that of ~/foo/foo.



      But is there a native command-line tool to do so, although I can achieve the goal with a function, too?







      share|improve this question













      Suppose that I have only the following in ~/foo:



      .
      ..
      foo


      With file managers if I cut the subfolder foo and paste it into ~ it automatically replaces the contents of ~/foo with that of ~/foo/foo.



      But is there a native command-line tool to do so, although I can achieve the goal with a function, too?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Apr 29 at 3:48









      G-Man

      11.5k82656




      11.5k82656









      asked Apr 29 at 2:55









      cvoret

      82




      82




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          I don’t know any way to do it in one step,
          but the easiest way around the problem is to remove the problem. 
          The fact that the two directories have the same name is a problem;
          so, rename one of them:



          mv foo foo2 && mv foo2/foo foo && rmdir foo2





          share|improve this answer



















          • 1




            Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
            – Stéphane Chazelas
            Apr 29 at 6:43











          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%2f440668%2fhow-do-i-replace-a-folder-with-its-only-subfolder-of-the-same-name-in-cli%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



          accepted










          I don’t know any way to do it in one step,
          but the easiest way around the problem is to remove the problem. 
          The fact that the two directories have the same name is a problem;
          so, rename one of them:



          mv foo foo2 && mv foo2/foo foo && rmdir foo2





          share|improve this answer



















          • 1




            Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
            – Stéphane Chazelas
            Apr 29 at 6:43















          up vote
          1
          down vote



          accepted










          I don’t know any way to do it in one step,
          but the easiest way around the problem is to remove the problem. 
          The fact that the two directories have the same name is a problem;
          so, rename one of them:



          mv foo foo2 && mv foo2/foo foo && rmdir foo2





          share|improve this answer



















          • 1




            Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
            – Stéphane Chazelas
            Apr 29 at 6:43













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          I don’t know any way to do it in one step,
          but the easiest way around the problem is to remove the problem. 
          The fact that the two directories have the same name is a problem;
          so, rename one of them:



          mv foo foo2 && mv foo2/foo foo && rmdir foo2





          share|improve this answer















          I don’t know any way to do it in one step,
          but the easiest way around the problem is to remove the problem. 
          The fact that the two directories have the same name is a problem;
          so, rename one of them:



          mv foo foo2 && mv foo2/foo foo && rmdir foo2






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Apr 29 at 4:32


























          answered Apr 29 at 3:54









          G-Man

          11.5k82656




          11.5k82656







          • 1




            Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
            – Stéphane Chazelas
            Apr 29 at 6:43













          • 1




            Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
            – Stéphane Chazelas
            Apr 29 at 6:43








          1




          1




          Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
          – Stéphane Chazelas
          Apr 29 at 6:43





          Or with GNU mv: mv -iT foo/foo foo2 && mv -T foo2 foo. One question would be: which foo would we like to preserve the metadata of?
          – Stéphane Chazelas
          Apr 29 at 6:43













           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440668%2fhow-do-i-replace-a-folder-with-its-only-subfolder-of-the-same-name-in-cli%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?