How do I move files out of nested subdirectories into another folder in ubuntu? (Trying to strip off many...











up vote
29
down vote

favorite
21












How do I move files and not directories into another folder/parent folder?



I have a folder structure that is extremely ugly, with some .mp3 files buried 6 levels deep in a sub-folder.



I want to end up with all of the files (mostly .mp3 but not all) in one directory, with no subdirectories at all, using Ubuntu.



Help?










share|improve this question




























    up vote
    29
    down vote

    favorite
    21












    How do I move files and not directories into another folder/parent folder?



    I have a folder structure that is extremely ugly, with some .mp3 files buried 6 levels deep in a sub-folder.



    I want to end up with all of the files (mostly .mp3 but not all) in one directory, with no subdirectories at all, using Ubuntu.



    Help?










    share|improve this question


























      up vote
      29
      down vote

      favorite
      21









      up vote
      29
      down vote

      favorite
      21






      21





      How do I move files and not directories into another folder/parent folder?



      I have a folder structure that is extremely ugly, with some .mp3 files buried 6 levels deep in a sub-folder.



      I want to end up with all of the files (mostly .mp3 but not all) in one directory, with no subdirectories at all, using Ubuntu.



      Help?










      share|improve this question















      How do I move files and not directories into another folder/parent folder?



      I have a folder structure that is extremely ugly, with some .mp3 files buried 6 levels deep in a sub-folder.



      I want to end up with all of the files (mostly .mp3 but not all) in one directory, with no subdirectories at all, using Ubuntu.



      Help?







      linux ubuntu file-management file-transfer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 2 '14 at 6:55









      Der Hochstapler

      67.1k48230283




      67.1k48230283










      asked Oct 12 '13 at 22:31









      Chris

      146123




      146123






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          39
          down vote













          There is a great answer in the askubuntu-QA.




          To do so, Open a terminal and execute this command:



          mv  -v ~/Downloads/* ~/Videos/


          It will move all the files and folders from Downloads folder to Videos
          folder.





          To Move all files, but not folders:



          But, If you are interested to move all files (but not folders) from
          Downloads folder to Videos folder, use this command



          find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/Videos


          To move only files from the Download folders, but not from sub-folders:



          If you want to move all files from the Downloads folder, but not any
          files within folders in the Download folder, use this command:



          find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videos


          here, -maxdepth option specifies how deep find should try,
          1 means, only the directory specified in the find command. You can
          try using 2, 3 also to test.



          See the Ubuntu find manpage for a detailed explanation.




          Source






          share|improve this answer























          • If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
            – Neoryder
            May 25 '16 at 10:30


















          up vote
          8
          down vote













          Solution



          find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +


          The command will find all regular files under /src/dir (including all subdirectories) and move them to the /dst/dir by use of the command mv. Just replace the directories by yours. Files with the same names will be renamed automatically.



          Selecting files to move



          If you want to move just MP3 files, add -iname "*.mp3" option to the find command after -type f.



          Comparison to the reply by c0dev



          Only the second command in the c0dev's reply answers the question. Below is how does it compare to this reply. The points 3. and 4. can be resolved in the other reply the same way as here.




          1. Except mv the solution with -exec + does not need to call an additional command like xargs or parallel and hand over the file names twice.

          2. The other reply will silently overwrite files which have the same name. Here the files will be automatically renamed thanks to the option --backup=numbered. Unfortunately these backups with suffix like ~3~ will be hidden in most of the file manages by default. Unfortunately mv does not allow changing of the suffix but it could be easily post-processed by additional commands. This is a GNU extension.

          3. Contrary to -print0 -exec command {} + is a part of IEEE Std 1003.1 (POSIX), ISO/IEC 9945 and The Single UNIX Specification standards. Thus it should be more portable. See IEEE Std 1003.1, 2004 Edition, IEEE Std 1003.1, 2013 Edition and 0000243: Add -print0 to "find". But anyway the required -t switch of mv is a GNU extension so the whole command is not portable between POSIX systems.


          Note: In the case find would be able to produce paths starting with - (I do not know of any such implementation of find at the moment.) the {} should be preceded by the end-of-options indicator: --.






          share|improve this answer























          • Error: find: missing argument to `-exec'
            – Chris
            Oct 12 '13 at 23:05










          • @Chris: You are right, it seems that {} must be as the last argument. Corrected.
            – pabouk
            Oct 12 '13 at 23:27










          • @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
            – pabouk
            Oct 15 '13 at 9:58










          • This is what I am running, and getting directory-not-found errors:
            – Chris
            Dec 30 '13 at 20:51










          • what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
            – Chris
            Dec 30 '13 at 21:09


















          up vote
          2
          down vote













          Unfortunately, I do not have a high enough reputation to comment on the marked solution. However, I wanted to caution others about an issue I ran into. It's quite amateur; however, when you're doing several things it may not come to mind at first. Hopefully, it will help others.



          Problem



          Variations of the following message was provided after initiating the command. The command then creates multiple files.



          mv: `/data/share/docs/src/dir/filename.ext' and `/data/share/docs/src/dst/filename.ext' are the same file


          Cause



          The /src is a parent of the /dst (e.g. /src/../dst/).



          Solution



          While there may be a better solution, I simply moved the files to a temporary directory outside of my /src and then reran the command to place them back within the /src/../dst directory I wanted them to end up in.






          share|improve this answer




























            up vote
            0
            down vote













            My one-liner - this works on Macs but should also do on any *nix.
            Start from parent directory.



            # Move files to parent and delete empty folders
            find . -not -type d -print0 | xargs -0J % mv -f % . ; find . -type d -depth -print0 | xargs -0 rm -rf


            The first part moves everything from all subfolders to the actual folder from where you staret the command; the second part checks if subdirs are empty (they should now :-) and deletes them so you get everything here with no subdirs.






            share|improve this answer























            • (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
              – Scott
              Oct 7 at 10:31













            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f658075%2fhow-do-i-move-files-out-of-nested-subdirectories-into-another-folder-in-ubuntu%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            39
            down vote













            There is a great answer in the askubuntu-QA.




            To do so, Open a terminal and execute this command:



            mv  -v ~/Downloads/* ~/Videos/


            It will move all the files and folders from Downloads folder to Videos
            folder.





            To Move all files, but not folders:



            But, If you are interested to move all files (but not folders) from
            Downloads folder to Videos folder, use this command



            find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/Videos


            To move only files from the Download folders, but not from sub-folders:



            If you want to move all files from the Downloads folder, but not any
            files within folders in the Download folder, use this command:



            find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videos


            here, -maxdepth option specifies how deep find should try,
            1 means, only the directory specified in the find command. You can
            try using 2, 3 also to test.



            See the Ubuntu find manpage for a detailed explanation.




            Source






            share|improve this answer























            • If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
              – Neoryder
              May 25 '16 at 10:30















            up vote
            39
            down vote













            There is a great answer in the askubuntu-QA.




            To do so, Open a terminal and execute this command:



            mv  -v ~/Downloads/* ~/Videos/


            It will move all the files and folders from Downloads folder to Videos
            folder.





            To Move all files, but not folders:



            But, If you are interested to move all files (but not folders) from
            Downloads folder to Videos folder, use this command



            find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/Videos


            To move only files from the Download folders, but not from sub-folders:



            If you want to move all files from the Downloads folder, but not any
            files within folders in the Download folder, use this command:



            find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videos


            here, -maxdepth option specifies how deep find should try,
            1 means, only the directory specified in the find command. You can
            try using 2, 3 also to test.



            See the Ubuntu find manpage for a detailed explanation.




            Source






            share|improve this answer























            • If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
              – Neoryder
              May 25 '16 at 10:30













            up vote
            39
            down vote










            up vote
            39
            down vote









            There is a great answer in the askubuntu-QA.




            To do so, Open a terminal and execute this command:



            mv  -v ~/Downloads/* ~/Videos/


            It will move all the files and folders from Downloads folder to Videos
            folder.





            To Move all files, but not folders:



            But, If you are interested to move all files (but not folders) from
            Downloads folder to Videos folder, use this command



            find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/Videos


            To move only files from the Download folders, but not from sub-folders:



            If you want to move all files from the Downloads folder, but not any
            files within folders in the Download folder, use this command:



            find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videos


            here, -maxdepth option specifies how deep find should try,
            1 means, only the directory specified in the find command. You can
            try using 2, 3 also to test.



            See the Ubuntu find manpage for a detailed explanation.




            Source






            share|improve this answer














            There is a great answer in the askubuntu-QA.




            To do so, Open a terminal and execute this command:



            mv  -v ~/Downloads/* ~/Videos/


            It will move all the files and folders from Downloads folder to Videos
            folder.





            To Move all files, but not folders:



            But, If you are interested to move all files (but not folders) from
            Downloads folder to Videos folder, use this command



            find ~/Downloads/ -type f -print0 | xargs -0 mv -t ~/Videos


            To move only files from the Download folders, but not from sub-folders:



            If you want to move all files from the Downloads folder, but not any
            files within folders in the Download folder, use this command:



            find ~/Downloads/ -maxdepth 1 -type f -print0 | xargs -0 mv -t ~/Videos


            here, -maxdepth option specifies how deep find should try,
            1 means, only the directory specified in the find command. You can
            try using 2, 3 also to test.



            See the Ubuntu find manpage for a detailed explanation.




            Source







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 13 '17 at 12:22









            Community

            1




            1










            answered Oct 12 '13 at 23:25









            Christian Woerz

            6,35511334




            6,35511334












            • If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
              – Neoryder
              May 25 '16 at 10:30


















            • If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
              – Neoryder
              May 25 '16 at 10:30
















            If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
            – Neoryder
            May 25 '16 at 10:30




            If what I want to do is copy all files to the folder will I just have to change mv to cp? I am new to linux
            – Neoryder
            May 25 '16 at 10:30












            up vote
            8
            down vote













            Solution



            find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +


            The command will find all regular files under /src/dir (including all subdirectories) and move them to the /dst/dir by use of the command mv. Just replace the directories by yours. Files with the same names will be renamed automatically.



            Selecting files to move



            If you want to move just MP3 files, add -iname "*.mp3" option to the find command after -type f.



            Comparison to the reply by c0dev



            Only the second command in the c0dev's reply answers the question. Below is how does it compare to this reply. The points 3. and 4. can be resolved in the other reply the same way as here.




            1. Except mv the solution with -exec + does not need to call an additional command like xargs or parallel and hand over the file names twice.

            2. The other reply will silently overwrite files which have the same name. Here the files will be automatically renamed thanks to the option --backup=numbered. Unfortunately these backups with suffix like ~3~ will be hidden in most of the file manages by default. Unfortunately mv does not allow changing of the suffix but it could be easily post-processed by additional commands. This is a GNU extension.

            3. Contrary to -print0 -exec command {} + is a part of IEEE Std 1003.1 (POSIX), ISO/IEC 9945 and The Single UNIX Specification standards. Thus it should be more portable. See IEEE Std 1003.1, 2004 Edition, IEEE Std 1003.1, 2013 Edition and 0000243: Add -print0 to "find". But anyway the required -t switch of mv is a GNU extension so the whole command is not portable between POSIX systems.


            Note: In the case find would be able to produce paths starting with - (I do not know of any such implementation of find at the moment.) the {} should be preceded by the end-of-options indicator: --.






            share|improve this answer























            • Error: find: missing argument to `-exec'
              – Chris
              Oct 12 '13 at 23:05










            • @Chris: You are right, it seems that {} must be as the last argument. Corrected.
              – pabouk
              Oct 12 '13 at 23:27










            • @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
              – pabouk
              Oct 15 '13 at 9:58










            • This is what I am running, and getting directory-not-found errors:
              – Chris
              Dec 30 '13 at 20:51










            • what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
              – Chris
              Dec 30 '13 at 21:09















            up vote
            8
            down vote













            Solution



            find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +


            The command will find all regular files under /src/dir (including all subdirectories) and move them to the /dst/dir by use of the command mv. Just replace the directories by yours. Files with the same names will be renamed automatically.



            Selecting files to move



            If you want to move just MP3 files, add -iname "*.mp3" option to the find command after -type f.



            Comparison to the reply by c0dev



            Only the second command in the c0dev's reply answers the question. Below is how does it compare to this reply. The points 3. and 4. can be resolved in the other reply the same way as here.




            1. Except mv the solution with -exec + does not need to call an additional command like xargs or parallel and hand over the file names twice.

            2. The other reply will silently overwrite files which have the same name. Here the files will be automatically renamed thanks to the option --backup=numbered. Unfortunately these backups with suffix like ~3~ will be hidden in most of the file manages by default. Unfortunately mv does not allow changing of the suffix but it could be easily post-processed by additional commands. This is a GNU extension.

            3. Contrary to -print0 -exec command {} + is a part of IEEE Std 1003.1 (POSIX), ISO/IEC 9945 and The Single UNIX Specification standards. Thus it should be more portable. See IEEE Std 1003.1, 2004 Edition, IEEE Std 1003.1, 2013 Edition and 0000243: Add -print0 to "find". But anyway the required -t switch of mv is a GNU extension so the whole command is not portable between POSIX systems.


            Note: In the case find would be able to produce paths starting with - (I do not know of any such implementation of find at the moment.) the {} should be preceded by the end-of-options indicator: --.






            share|improve this answer























            • Error: find: missing argument to `-exec'
              – Chris
              Oct 12 '13 at 23:05










            • @Chris: You are right, it seems that {} must be as the last argument. Corrected.
              – pabouk
              Oct 12 '13 at 23:27










            • @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
              – pabouk
              Oct 15 '13 at 9:58










            • This is what I am running, and getting directory-not-found errors:
              – Chris
              Dec 30 '13 at 20:51










            • what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
              – Chris
              Dec 30 '13 at 21:09













            up vote
            8
            down vote










            up vote
            8
            down vote









            Solution



            find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +


            The command will find all regular files under /src/dir (including all subdirectories) and move them to the /dst/dir by use of the command mv. Just replace the directories by yours. Files with the same names will be renamed automatically.



            Selecting files to move



            If you want to move just MP3 files, add -iname "*.mp3" option to the find command after -type f.



            Comparison to the reply by c0dev



            Only the second command in the c0dev's reply answers the question. Below is how does it compare to this reply. The points 3. and 4. can be resolved in the other reply the same way as here.




            1. Except mv the solution with -exec + does not need to call an additional command like xargs or parallel and hand over the file names twice.

            2. The other reply will silently overwrite files which have the same name. Here the files will be automatically renamed thanks to the option --backup=numbered. Unfortunately these backups with suffix like ~3~ will be hidden in most of the file manages by default. Unfortunately mv does not allow changing of the suffix but it could be easily post-processed by additional commands. This is a GNU extension.

            3. Contrary to -print0 -exec command {} + is a part of IEEE Std 1003.1 (POSIX), ISO/IEC 9945 and The Single UNIX Specification standards. Thus it should be more portable. See IEEE Std 1003.1, 2004 Edition, IEEE Std 1003.1, 2013 Edition and 0000243: Add -print0 to "find". But anyway the required -t switch of mv is a GNU extension so the whole command is not portable between POSIX systems.


            Note: In the case find would be able to produce paths starting with - (I do not know of any such implementation of find at the moment.) the {} should be preceded by the end-of-options indicator: --.






            share|improve this answer














            Solution



            find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +


            The command will find all regular files under /src/dir (including all subdirectories) and move them to the /dst/dir by use of the command mv. Just replace the directories by yours. Files with the same names will be renamed automatically.



            Selecting files to move



            If you want to move just MP3 files, add -iname "*.mp3" option to the find command after -type f.



            Comparison to the reply by c0dev



            Only the second command in the c0dev's reply answers the question. Below is how does it compare to this reply. The points 3. and 4. can be resolved in the other reply the same way as here.




            1. Except mv the solution with -exec + does not need to call an additional command like xargs or parallel and hand over the file names twice.

            2. The other reply will silently overwrite files which have the same name. Here the files will be automatically renamed thanks to the option --backup=numbered. Unfortunately these backups with suffix like ~3~ will be hidden in most of the file manages by default. Unfortunately mv does not allow changing of the suffix but it could be easily post-processed by additional commands. This is a GNU extension.

            3. Contrary to -print0 -exec command {} + is a part of IEEE Std 1003.1 (POSIX), ISO/IEC 9945 and The Single UNIX Specification standards. Thus it should be more portable. See IEEE Std 1003.1, 2004 Edition, IEEE Std 1003.1, 2013 Edition and 0000243: Add -print0 to "find". But anyway the required -t switch of mv is a GNU extension so the whole command is not portable between POSIX systems.


            Note: In the case find would be able to produce paths starting with - (I do not know of any such implementation of find at the moment.) the {} should be preceded by the end-of-options indicator: --.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 3 '14 at 20:59

























            answered Oct 12 '13 at 22:37









            pabouk

            4,85053044




            4,85053044












            • Error: find: missing argument to `-exec'
              – Chris
              Oct 12 '13 at 23:05










            • @Chris: You are right, it seems that {} must be as the last argument. Corrected.
              – pabouk
              Oct 12 '13 at 23:27










            • @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
              – pabouk
              Oct 15 '13 at 9:58










            • This is what I am running, and getting directory-not-found errors:
              – Chris
              Dec 30 '13 at 20:51










            • what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
              – Chris
              Dec 30 '13 at 21:09


















            • Error: find: missing argument to `-exec'
              – Chris
              Oct 12 '13 at 23:05










            • @Chris: You are right, it seems that {} must be as the last argument. Corrected.
              – pabouk
              Oct 12 '13 at 23:27










            • @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
              – pabouk
              Oct 15 '13 at 9:58










            • This is what I am running, and getting directory-not-found errors:
              – Chris
              Dec 30 '13 at 20:51










            • what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
              – Chris
              Dec 30 '13 at 21:09
















            Error: find: missing argument to `-exec'
            – Chris
            Oct 12 '13 at 23:05




            Error: find: missing argument to `-exec'
            – Chris
            Oct 12 '13 at 23:05












            @Chris: You are right, it seems that {} must be as the last argument. Corrected.
            – pabouk
            Oct 12 '13 at 23:27




            @Chris: You are right, it seems that {} must be as the last argument. Corrected.
            – pabouk
            Oct 12 '13 at 23:27












            @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
            – pabouk
            Oct 15 '13 at 9:58




            @Chris: Does it work now as you wished? If yes, you can probably accept the answer so your question does not show up as "not-resolved".
            – pabouk
            Oct 15 '13 at 9:58












            This is what I am running, and getting directory-not-found errors:
            – Chris
            Dec 30 '13 at 20:51




            This is what I am running, and getting directory-not-found errors:
            – Chris
            Dec 30 '13 at 20:51












            what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
            – Chris
            Dec 30 '13 at 21:09




            what I am running: clstal@clap:~$ ls 1st script.R Firefox_wallpaper.png part1vidproj zotero pdf manager Desktop mozilla.pdf Pictures Documents parent Videos clstal@clap:~$ find /source/directory -type f -exec mv -t /destination/directory {} + find: `/source/directory': No such file or directory
            – Chris
            Dec 30 '13 at 21:09










            up vote
            2
            down vote













            Unfortunately, I do not have a high enough reputation to comment on the marked solution. However, I wanted to caution others about an issue I ran into. It's quite amateur; however, when you're doing several things it may not come to mind at first. Hopefully, it will help others.



            Problem



            Variations of the following message was provided after initiating the command. The command then creates multiple files.



            mv: `/data/share/docs/src/dir/filename.ext' and `/data/share/docs/src/dst/filename.ext' are the same file


            Cause



            The /src is a parent of the /dst (e.g. /src/../dst/).



            Solution



            While there may be a better solution, I simply moved the files to a temporary directory outside of my /src and then reran the command to place them back within the /src/../dst directory I wanted them to end up in.






            share|improve this answer

























              up vote
              2
              down vote













              Unfortunately, I do not have a high enough reputation to comment on the marked solution. However, I wanted to caution others about an issue I ran into. It's quite amateur; however, when you're doing several things it may not come to mind at first. Hopefully, it will help others.



              Problem



              Variations of the following message was provided after initiating the command. The command then creates multiple files.



              mv: `/data/share/docs/src/dir/filename.ext' and `/data/share/docs/src/dst/filename.ext' are the same file


              Cause



              The /src is a parent of the /dst (e.g. /src/../dst/).



              Solution



              While there may be a better solution, I simply moved the files to a temporary directory outside of my /src and then reran the command to place them back within the /src/../dst directory I wanted them to end up in.






              share|improve this answer























                up vote
                2
                down vote










                up vote
                2
                down vote









                Unfortunately, I do not have a high enough reputation to comment on the marked solution. However, I wanted to caution others about an issue I ran into. It's quite amateur; however, when you're doing several things it may not come to mind at first. Hopefully, it will help others.



                Problem



                Variations of the following message was provided after initiating the command. The command then creates multiple files.



                mv: `/data/share/docs/src/dir/filename.ext' and `/data/share/docs/src/dst/filename.ext' are the same file


                Cause



                The /src is a parent of the /dst (e.g. /src/../dst/).



                Solution



                While there may be a better solution, I simply moved the files to a temporary directory outside of my /src and then reran the command to place them back within the /src/../dst directory I wanted them to end up in.






                share|improve this answer












                Unfortunately, I do not have a high enough reputation to comment on the marked solution. However, I wanted to caution others about an issue I ran into. It's quite amateur; however, when you're doing several things it may not come to mind at first. Hopefully, it will help others.



                Problem



                Variations of the following message was provided after initiating the command. The command then creates multiple files.



                mv: `/data/share/docs/src/dir/filename.ext' and `/data/share/docs/src/dst/filename.ext' are the same file


                Cause



                The /src is a parent of the /dst (e.g. /src/../dst/).



                Solution



                While there may be a better solution, I simply moved the files to a temporary directory outside of my /src and then reran the command to place them back within the /src/../dst directory I wanted them to end up in.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 16 '15 at 13:58









                MackAltman

                211




                211






















                    up vote
                    0
                    down vote













                    My one-liner - this works on Macs but should also do on any *nix.
                    Start from parent directory.



                    # Move files to parent and delete empty folders
                    find . -not -type d -print0 | xargs -0J % mv -f % . ; find . -type d -depth -print0 | xargs -0 rm -rf


                    The first part moves everything from all subfolders to the actual folder from where you staret the command; the second part checks if subdirs are empty (they should now :-) and deletes them so you get everything here with no subdirs.






                    share|improve this answer























                    • (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
                      – Scott
                      Oct 7 at 10:31

















                    up vote
                    0
                    down vote













                    My one-liner - this works on Macs but should also do on any *nix.
                    Start from parent directory.



                    # Move files to parent and delete empty folders
                    find . -not -type d -print0 | xargs -0J % mv -f % . ; find . -type d -depth -print0 | xargs -0 rm -rf


                    The first part moves everything from all subfolders to the actual folder from where you staret the command; the second part checks if subdirs are empty (they should now :-) and deletes them so you get everything here with no subdirs.






                    share|improve this answer























                    • (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
                      – Scott
                      Oct 7 at 10:31















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    My one-liner - this works on Macs but should also do on any *nix.
                    Start from parent directory.



                    # Move files to parent and delete empty folders
                    find . -not -type d -print0 | xargs -0J % mv -f % . ; find . -type d -depth -print0 | xargs -0 rm -rf


                    The first part moves everything from all subfolders to the actual folder from where you staret the command; the second part checks if subdirs are empty (they should now :-) and deletes them so you get everything here with no subdirs.






                    share|improve this answer














                    My one-liner - this works on Macs but should also do on any *nix.
                    Start from parent directory.



                    # Move files to parent and delete empty folders
                    find . -not -type d -print0 | xargs -0J % mv -f % . ; find . -type d -depth -print0 | xargs -0 rm -rf


                    The first part moves everything from all subfolders to the actual folder from where you staret the command; the second part checks if subdirs are empty (they should now :-) and deletes them so you get everything here with no subdirs.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 4 at 12:41

























                    answered Oct 7 at 9:52









                    X-File

                    114




                    114












                    • (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
                      – Scott
                      Oct 7 at 10:31




















                    • (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
                      – Scott
                      Oct 7 at 10:31


















                    (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
                    – Scott
                    Oct 7 at 10:31






                    (1) Please explain what your answer does, and any advantages it has over the other answers (which are very similar).  Please do not respond in comments; edit your answer to make it clearer and more complete. (2) Note that the -not operator is non-standard, so your command is less portable than the others.
                    – Scott
                    Oct 7 at 10:31




















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f658075%2fhow-do-i-move-files-out-of-nested-subdirectories-into-another-folder-in-ubuntu%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Probability when a professor distributes a quiz and homework assignment to a class of n students.

                    Aardman Animations

                    Are they similar matrix