Move Files from Directory up one level

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











up vote
0
down vote

favorite












I have a filestructure with several subfolders where I'd like to search for all subfolder containing a certain string ("sub*") and then move all of the files in these found folders up one level from each of their respective location. And even potentially delete the then empty folder but I could do that with a second step as well.










share|improve this question

























    up vote
    0
    down vote

    favorite












    I have a filestructure with several subfolders where I'd like to search for all subfolder containing a certain string ("sub*") and then move all of the files in these found folders up one level from each of their respective location. And even potentially delete the then empty folder but I could do that with a second step as well.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a filestructure with several subfolders where I'd like to search for all subfolder containing a certain string ("sub*") and then move all of the files in these found folders up one level from each of their respective location. And even potentially delete the then empty folder but I could do that with a second step as well.










      share|improve this question













      I have a filestructure with several subfolders where I'd like to search for all subfolder containing a certain string ("sub*") and then move all of the files in these found folders up one level from each of their respective location. And even potentially delete the then empty folder but I could do that with a second step as well.







      find recursive move






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 15 '16 at 12:21









      Fabian

      85




      85




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          This should do it:



          find /path/to/base/folder/ -type d -name 'sub*' -exec bash -c 'mv /* "$(dirname )"' ;


          NOTE: this will not move hidden files (whose name start with .)






          share|improve this answer






















          • What is "dirname" in this supposed to be?
            – Fabian
            Dec 15 '16 at 12:36






          • 1




            This is the name of a command, see man dirname
            – NarÅ«nasK
            Dec 15 '16 at 12:36







          • 1




            Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
            – Fabian
            Dec 15 '16 at 12:44

















          up vote
          0
          down vote













          find /path/to -type f -execdir mv .. ;




          share








          New contributor




          LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















            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%2f330600%2fmove-files-from-directory-up-one-level%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            This should do it:



            find /path/to/base/folder/ -type d -name 'sub*' -exec bash -c 'mv /* "$(dirname )"' ;


            NOTE: this will not move hidden files (whose name start with .)






            share|improve this answer






















            • What is "dirname" in this supposed to be?
              – Fabian
              Dec 15 '16 at 12:36






            • 1




              This is the name of a command, see man dirname
              – NarÅ«nasK
              Dec 15 '16 at 12:36







            • 1




              Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
              – Fabian
              Dec 15 '16 at 12:44














            up vote
            0
            down vote



            accepted










            This should do it:



            find /path/to/base/folder/ -type d -name 'sub*' -exec bash -c 'mv /* "$(dirname )"' ;


            NOTE: this will not move hidden files (whose name start with .)






            share|improve this answer






















            • What is "dirname" in this supposed to be?
              – Fabian
              Dec 15 '16 at 12:36






            • 1




              This is the name of a command, see man dirname
              – NarÅ«nasK
              Dec 15 '16 at 12:36







            • 1




              Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
              – Fabian
              Dec 15 '16 at 12:44












            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            This should do it:



            find /path/to/base/folder/ -type d -name 'sub*' -exec bash -c 'mv /* "$(dirname )"' ;


            NOTE: this will not move hidden files (whose name start with .)






            share|improve this answer














            This should do it:



            find /path/to/base/folder/ -type d -name 'sub*' -exec bash -c 'mv /* "$(dirname )"' ;


            NOTE: this will not move hidden files (whose name start with .)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 16 '16 at 21:52

























            answered Dec 15 '16 at 12:35









            NarūnasK

            8121619




            8121619











            • What is "dirname" in this supposed to be?
              – Fabian
              Dec 15 '16 at 12:36






            • 1




              This is the name of a command, see man dirname
              – NarÅ«nasK
              Dec 15 '16 at 12:36







            • 1




              Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
              – Fabian
              Dec 15 '16 at 12:44
















            • What is "dirname" in this supposed to be?
              – Fabian
              Dec 15 '16 at 12:36






            • 1




              This is the name of a command, see man dirname
              – NarÅ«nasK
              Dec 15 '16 at 12:36







            • 1




              Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
              – Fabian
              Dec 15 '16 at 12:44















            What is "dirname" in this supposed to be?
            – Fabian
            Dec 15 '16 at 12:36




            What is "dirname" in this supposed to be?
            – Fabian
            Dec 15 '16 at 12:36




            1




            1




            This is the name of a command, see man dirname
            – NarÅ«nasK
            Dec 15 '16 at 12:36





            This is the name of a command, see man dirname
            – NarÅ«nasK
            Dec 15 '16 at 12:36





            1




            1




            Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
            – Fabian
            Dec 15 '16 at 12:44




            Okay, i tried it out. Unfortunately it does not do what I want. it moves the Folder found with "find" up one directory. However what i need is the content IN the folder to be moved up one level (so basically then on the same level as the folder)
            – Fabian
            Dec 15 '16 at 12:44












            up vote
            0
            down vote













            find /path/to -type f -execdir mv .. ;




            share








            New contributor




            LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              up vote
              0
              down vote













              find /path/to -type f -execdir mv .. ;




              share








              New contributor




              LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.



















                up vote
                0
                down vote










                up vote
                0
                down vote









                find /path/to -type f -execdir mv .. ;




                share








                New contributor




                LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                find /path/to -type f -execdir mv .. ;





                share








                New contributor




                LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.








                share


                share






                New contributor




                LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered 6 mins ago









                LeoWinterDE

                11




                11




                New contributor




                LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                LeoWinterDE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f330600%2fmove-files-from-directory-up-one-level%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?