How to move multiple files at once to a specific destination directory?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







133















I got a bunch of files in some directory (along with many other files) that I want to move.



Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.



But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?










share|improve this question































    133















    I got a bunch of files in some directory (along with many other files) that I want to move.



    Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.



    But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?










    share|improve this question



























      133












      133








      133


      51






      I got a bunch of files in some directory (along with many other files) that I want to move.



      Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.



      But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?










      share|improve this question
















      I got a bunch of files in some directory (along with many other files) that I want to move.



      Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.



      But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?







      command-line mv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 24 '18 at 9:47









      muru

      1




      1










      asked Nov 8 '12 at 13:13









      gilad hochgilad hoch

      780299




      780299






















          12 Answers
          12






          active

          oldest

          votes


















          95














          If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:



          mv *IDENTIFIER* ~/YourPath/


          * is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.



          This will move all the files that contain the IDENTIFIER you specified.






          share|improve this answer

































            184














            You could use



            mv -t DESTINATION file1 file2 file3



            and



            mv -t DESTINATION `ls|grep IDENTIFIER`



            works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.






            share|improve this answer





















            • 5





              works on linux, not sure if it will work on mac

              – Alexander Mills
              Dec 10 '16 at 20:25






            • 3





              works on mac and git bash via git for windwows.

              – Brandt Solovij
              Feb 23 '17 at 12:55






            • 7





              Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

              – Sheljohn
              Jul 23 '17 at 15:29








            • 2





              -1 for second approach as it will fall for files including new lines

              – αғsнιη
              Sep 7 '17 at 15:33






            • 3





              Why you shouldn't parse the output of ls.

              – dessert
              Dec 1 '17 at 9:42



















            22














            You can use wildcards.



            Example: To move all files having extension .doc



            mv *.doc /path/to/dest/folder/



            This will move all doc file under the current directory to the specific destination.



            Edit



            To answer the comment.



            mv *.ext *.xml *.txt /path/to/dest/folder/






            share|improve this answer





















            • 2





              but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

              – gilad hoch
              Nov 8 '12 at 13:25











            • @giladhoch How about the edited one?

              – Achu
              Nov 8 '12 at 13:36











            • @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

              – ignite
              Nov 8 '12 at 13:47











            • won't work since there are other .xml files (for instance) i do'nt want to move.

              – gilad hoch
              Nov 8 '12 at 13:50



















            20














            In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
            first go to the directory that contains the files you want to move



            mv file1.ext1 file2.ext2 file3.ext3.. /destination/


            In case the files are scattered in different directories, you only need to specify the path for each file in the move command






            share|improve this answer































              10














              I use tuomaz's technique, but slightly modified:



              mv file1 file2 file3 -t DESTINATION


              I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:



              mv file1 DESTINATION





              share|improve this answer
























              • The man page for mv doesn't mention a -t option.

                – Noumenon
                Oct 24 '16 at 3:25






              • 1





                linux.die.net/man/1/mv yes it does

                – geoyws
                Feb 20 '17 at 4:00



















              7














              Use this command:



              mv `ls|grep IDENTIFIER` /path/to/dest/folder  


              However, ls is not recommended for this kind of use. Use find command instead.






              share|improve this answer





















              • 8





                ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                – NorTicUs
                Nov 8 '12 at 13:48











              • This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                – ignite
                Nov 8 '12 at 13:50






              • 3





                As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                – Paddy Landau
                Nov 13 '12 at 14:27











              • don't parse ls

                – Zanna
                Sep 7 '17 at 15:15



















              5














              If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:



              ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/


              The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.






              share|improve this answer
























              • This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                – AggieBill
                Nov 14 '12 at 10:11






              • 1





                +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                – Joe
                Nov 14 '12 at 23:33





















              5














              If the files are in the same dir you can use



              mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/


              (tested in Ubuntu 16.04)






              share|improve this answer





















              • 1





                This doesn't really add something to the existing answers, don't you think?

                – dessert
                Dec 1 '17 at 9:46






              • 1





                just eliminates the need to specify full path to dir for each file

                – Sruli
                Dec 1 '17 at 11:22





















              3














              find -type f -name "[range]" -exec mv {} target-directory ';'


              this command will move file names with any pattern/range to target-directory.



              eg.



              find -type f -name "file[1-50000]" -exec mv {} target-directory ';'


              it will move files with names like file1, file2 ... file50000 to target-directory.






              share|improve this answer

































                2














                You can use the output from ls to input into mv commnad



                mv $(ls | grep IDENTIFIER) /path/to/dest/dir



                The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.






                share|improve this answer



















                • 1





                  don't parse ls

                  – Zanna
                  Sep 7 '17 at 15:14



















                1














                Using this command you can move multiple files.



                mv SourceFilenames ~DestinationPath






                share|improve this answer































                  1














                  Easiest way is like this



                  mv {file1,file2,file3} DESTINATION


                  or directory



                  mv {directory1,directory2,directory3} DESTINATION


                  or both files and directories



                  mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION


                  Hope this helps






                  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',
                    autoActivateHeartbeat: false,
                    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%2faskubuntu.com%2fquestions%2f214560%2fhow-to-move-multiple-files-at-once-to-a-specific-destination-directory%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    12 Answers
                    12






                    active

                    oldest

                    votes








                    12 Answers
                    12






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    95














                    If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:



                    mv *IDENTIFIER* ~/YourPath/


                    * is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.



                    This will move all the files that contain the IDENTIFIER you specified.






                    share|improve this answer






























                      95














                      If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:



                      mv *IDENTIFIER* ~/YourPath/


                      * is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.



                      This will move all the files that contain the IDENTIFIER you specified.






                      share|improve this answer




























                        95












                        95








                        95







                        If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:



                        mv *IDENTIFIER* ~/YourPath/


                        * is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.



                        This will move all the files that contain the IDENTIFIER you specified.






                        share|improve this answer















                        If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:



                        mv *IDENTIFIER* ~/YourPath/


                        * is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.



                        This will move all the files that contain the IDENTIFIER you specified.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 11 '12 at 17:07

























                        answered Nov 8 '12 at 13:33









                        Evandro SilvaEvandro Silva

                        6,63852944




                        6,63852944

























                            184














                            You could use



                            mv -t DESTINATION file1 file2 file3



                            and



                            mv -t DESTINATION `ls|grep IDENTIFIER`



                            works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.






                            share|improve this answer





















                            • 5





                              works on linux, not sure if it will work on mac

                              – Alexander Mills
                              Dec 10 '16 at 20:25






                            • 3





                              works on mac and git bash via git for windwows.

                              – Brandt Solovij
                              Feb 23 '17 at 12:55






                            • 7





                              Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

                              – Sheljohn
                              Jul 23 '17 at 15:29








                            • 2





                              -1 for second approach as it will fall for files including new lines

                              – αғsнιη
                              Sep 7 '17 at 15:33






                            • 3





                              Why you shouldn't parse the output of ls.

                              – dessert
                              Dec 1 '17 at 9:42
















                            184














                            You could use



                            mv -t DESTINATION file1 file2 file3



                            and



                            mv -t DESTINATION `ls|grep IDENTIFIER`



                            works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.






                            share|improve this answer





















                            • 5





                              works on linux, not sure if it will work on mac

                              – Alexander Mills
                              Dec 10 '16 at 20:25






                            • 3





                              works on mac and git bash via git for windwows.

                              – Brandt Solovij
                              Feb 23 '17 at 12:55






                            • 7





                              Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

                              – Sheljohn
                              Jul 23 '17 at 15:29








                            • 2





                              -1 for second approach as it will fall for files including new lines

                              – αғsнιη
                              Sep 7 '17 at 15:33






                            • 3





                              Why you shouldn't parse the output of ls.

                              – dessert
                              Dec 1 '17 at 9:42














                            184












                            184








                            184







                            You could use



                            mv -t DESTINATION file1 file2 file3



                            and



                            mv -t DESTINATION `ls|grep IDENTIFIER`



                            works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.






                            share|improve this answer















                            You could use



                            mv -t DESTINATION file1 file2 file3



                            and



                            mv -t DESTINATION `ls|grep IDENTIFIER`



                            works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 14 '12 at 11:13

























                            answered Nov 14 '12 at 11:07









                            tuomaztuomaz

                            1,865273




                            1,865273








                            • 5





                              works on linux, not sure if it will work on mac

                              – Alexander Mills
                              Dec 10 '16 at 20:25






                            • 3





                              works on mac and git bash via git for windwows.

                              – Brandt Solovij
                              Feb 23 '17 at 12:55






                            • 7





                              Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

                              – Sheljohn
                              Jul 23 '17 at 15:29








                            • 2





                              -1 for second approach as it will fall for files including new lines

                              – αғsнιη
                              Sep 7 '17 at 15:33






                            • 3





                              Why you shouldn't parse the output of ls.

                              – dessert
                              Dec 1 '17 at 9:42














                            • 5





                              works on linux, not sure if it will work on mac

                              – Alexander Mills
                              Dec 10 '16 at 20:25






                            • 3





                              works on mac and git bash via git for windwows.

                              – Brandt Solovij
                              Feb 23 '17 at 12:55






                            • 7





                              Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

                              – Sheljohn
                              Jul 23 '17 at 15:29








                            • 2





                              -1 for second approach as it will fall for files including new lines

                              – αғsнιη
                              Sep 7 '17 at 15:33






                            • 3





                              Why you shouldn't parse the output of ls.

                              – dessert
                              Dec 1 '17 at 9:42








                            5




                            5





                            works on linux, not sure if it will work on mac

                            – Alexander Mills
                            Dec 10 '16 at 20:25





                            works on linux, not sure if it will work on mac

                            – Alexander Mills
                            Dec 10 '16 at 20:25




                            3




                            3





                            works on mac and git bash via git for windwows.

                            – Brandt Solovij
                            Feb 23 '17 at 12:55





                            works on mac and git bash via git for windwows.

                            – Brandt Solovij
                            Feb 23 '17 at 12:55




                            7




                            7





                            Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

                            – Sheljohn
                            Jul 23 '17 at 15:29







                            Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e. mv file1 file2 ... destination

                            – Sheljohn
                            Jul 23 '17 at 15:29






                            2




                            2





                            -1 for second approach as it will fall for files including new lines

                            – αғsнιη
                            Sep 7 '17 at 15:33





                            -1 for second approach as it will fall for files including new lines

                            – αғsнιη
                            Sep 7 '17 at 15:33




                            3




                            3





                            Why you shouldn't parse the output of ls.

                            – dessert
                            Dec 1 '17 at 9:42





                            Why you shouldn't parse the output of ls.

                            – dessert
                            Dec 1 '17 at 9:42











                            22














                            You can use wildcards.



                            Example: To move all files having extension .doc



                            mv *.doc /path/to/dest/folder/



                            This will move all doc file under the current directory to the specific destination.



                            Edit



                            To answer the comment.



                            mv *.ext *.xml *.txt /path/to/dest/folder/






                            share|improve this answer





















                            • 2





                              but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

                              – gilad hoch
                              Nov 8 '12 at 13:25











                            • @giladhoch How about the edited one?

                              – Achu
                              Nov 8 '12 at 13:36











                            • @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

                              – ignite
                              Nov 8 '12 at 13:47











                            • won't work since there are other .xml files (for instance) i do'nt want to move.

                              – gilad hoch
                              Nov 8 '12 at 13:50
















                            22














                            You can use wildcards.



                            Example: To move all files having extension .doc



                            mv *.doc /path/to/dest/folder/



                            This will move all doc file under the current directory to the specific destination.



                            Edit



                            To answer the comment.



                            mv *.ext *.xml *.txt /path/to/dest/folder/






                            share|improve this answer





















                            • 2





                              but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

                              – gilad hoch
                              Nov 8 '12 at 13:25











                            • @giladhoch How about the edited one?

                              – Achu
                              Nov 8 '12 at 13:36











                            • @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

                              – ignite
                              Nov 8 '12 at 13:47











                            • won't work since there are other .xml files (for instance) i do'nt want to move.

                              – gilad hoch
                              Nov 8 '12 at 13:50














                            22












                            22








                            22







                            You can use wildcards.



                            Example: To move all files having extension .doc



                            mv *.doc /path/to/dest/folder/



                            This will move all doc file under the current directory to the specific destination.



                            Edit



                            To answer the comment.



                            mv *.ext *.xml *.txt /path/to/dest/folder/






                            share|improve this answer















                            You can use wildcards.



                            Example: To move all files having extension .doc



                            mv *.doc /path/to/dest/folder/



                            This will move all doc file under the current directory to the specific destination.



                            Edit



                            To answer the comment.



                            mv *.ext *.xml *.txt /path/to/dest/folder/







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 8 '12 at 13:33

























                            answered Nov 8 '12 at 13:21









                            AchuAchu

                            16.2k136499




                            16.2k136499








                            • 2





                              but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

                              – gilad hoch
                              Nov 8 '12 at 13:25











                            • @giladhoch How about the edited one?

                              – Achu
                              Nov 8 '12 at 13:36











                            • @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

                              – ignite
                              Nov 8 '12 at 13:47











                            • won't work since there are other .xml files (for instance) i do'nt want to move.

                              – gilad hoch
                              Nov 8 '12 at 13:50














                            • 2





                              but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

                              – gilad hoch
                              Nov 8 '12 at 13:25











                            • @giladhoch How about the edited one?

                              – Achu
                              Nov 8 '12 at 13:36











                            • @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

                              – ignite
                              Nov 8 '12 at 13:47











                            • won't work since there are other .xml files (for instance) i do'nt want to move.

                              – gilad hoch
                              Nov 8 '12 at 13:50








                            2




                            2





                            but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

                            – gilad hoch
                            Nov 8 '12 at 13:25





                            but the list of files to move is not determined by extension. some of the files are named: ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.

                            – gilad hoch
                            Nov 8 '12 at 13:25













                            @giladhoch How about the edited one?

                            – Achu
                            Nov 8 '12 at 13:36





                            @giladhoch How about the edited one?

                            – Achu
                            Nov 8 '12 at 13:36













                            @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

                            – ignite
                            Nov 8 '12 at 13:47





                            @gliadhoch If you are so comfortable using grep, you can see my answer above/below.

                            – ignite
                            Nov 8 '12 at 13:47













                            won't work since there are other .xml files (for instance) i do'nt want to move.

                            – gilad hoch
                            Nov 8 '12 at 13:50





                            won't work since there are other .xml files (for instance) i do'nt want to move.

                            – gilad hoch
                            Nov 8 '12 at 13:50











                            20














                            In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
                            first go to the directory that contains the files you want to move



                            mv file1.ext1 file2.ext2 file3.ext3.. /destination/


                            In case the files are scattered in different directories, you only need to specify the path for each file in the move command






                            share|improve this answer




























                              20














                              In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
                              first go to the directory that contains the files you want to move



                              mv file1.ext1 file2.ext2 file3.ext3.. /destination/


                              In case the files are scattered in different directories, you only need to specify the path for each file in the move command






                              share|improve this answer


























                                20












                                20








                                20







                                In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
                                first go to the directory that contains the files you want to move



                                mv file1.ext1 file2.ext2 file3.ext3.. /destination/


                                In case the files are scattered in different directories, you only need to specify the path for each file in the move command






                                share|improve this answer













                                In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
                                first go to the directory that contains the files you want to move



                                mv file1.ext1 file2.ext2 file3.ext3.. /destination/


                                In case the files are scattered in different directories, you only need to specify the path for each file in the move command







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 26 '14 at 4:03









                                Ismail AL-taharwaIsmail AL-taharwa

                                30122




                                30122























                                    10














                                    I use tuomaz's technique, but slightly modified:



                                    mv file1 file2 file3 -t DESTINATION


                                    I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:



                                    mv file1 DESTINATION





                                    share|improve this answer
























                                    • The man page for mv doesn't mention a -t option.

                                      – Noumenon
                                      Oct 24 '16 at 3:25






                                    • 1





                                      linux.die.net/man/1/mv yes it does

                                      – geoyws
                                      Feb 20 '17 at 4:00
















                                    10














                                    I use tuomaz's technique, but slightly modified:



                                    mv file1 file2 file3 -t DESTINATION


                                    I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:



                                    mv file1 DESTINATION





                                    share|improve this answer
























                                    • The man page for mv doesn't mention a -t option.

                                      – Noumenon
                                      Oct 24 '16 at 3:25






                                    • 1





                                      linux.die.net/man/1/mv yes it does

                                      – geoyws
                                      Feb 20 '17 at 4:00














                                    10












                                    10








                                    10







                                    I use tuomaz's technique, but slightly modified:



                                    mv file1 file2 file3 -t DESTINATION


                                    I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:



                                    mv file1 DESTINATION





                                    share|improve this answer













                                    I use tuomaz's technique, but slightly modified:



                                    mv file1 file2 file3 -t DESTINATION


                                    I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:



                                    mv file1 DESTINATION






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jan 20 '15 at 16:11









                                    Blake FrederickBlake Frederick

                                    20124




                                    20124













                                    • The man page for mv doesn't mention a -t option.

                                      – Noumenon
                                      Oct 24 '16 at 3:25






                                    • 1





                                      linux.die.net/man/1/mv yes it does

                                      – geoyws
                                      Feb 20 '17 at 4:00



















                                    • The man page for mv doesn't mention a -t option.

                                      – Noumenon
                                      Oct 24 '16 at 3:25






                                    • 1





                                      linux.die.net/man/1/mv yes it does

                                      – geoyws
                                      Feb 20 '17 at 4:00

















                                    The man page for mv doesn't mention a -t option.

                                    – Noumenon
                                    Oct 24 '16 at 3:25





                                    The man page for mv doesn't mention a -t option.

                                    – Noumenon
                                    Oct 24 '16 at 3:25




                                    1




                                    1





                                    linux.die.net/man/1/mv yes it does

                                    – geoyws
                                    Feb 20 '17 at 4:00





                                    linux.die.net/man/1/mv yes it does

                                    – geoyws
                                    Feb 20 '17 at 4:00











                                    7














                                    Use this command:



                                    mv `ls|grep IDENTIFIER` /path/to/dest/folder  


                                    However, ls is not recommended for this kind of use. Use find command instead.






                                    share|improve this answer





















                                    • 8





                                      ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                                      – NorTicUs
                                      Nov 8 '12 at 13:48











                                    • This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                                      – ignite
                                      Nov 8 '12 at 13:50






                                    • 3





                                      As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                                      – Paddy Landau
                                      Nov 13 '12 at 14:27











                                    • don't parse ls

                                      – Zanna
                                      Sep 7 '17 at 15:15
















                                    7














                                    Use this command:



                                    mv `ls|grep IDENTIFIER` /path/to/dest/folder  


                                    However, ls is not recommended for this kind of use. Use find command instead.






                                    share|improve this answer





















                                    • 8





                                      ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                                      – NorTicUs
                                      Nov 8 '12 at 13:48











                                    • This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                                      – ignite
                                      Nov 8 '12 at 13:50






                                    • 3





                                      As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                                      – Paddy Landau
                                      Nov 13 '12 at 14:27











                                    • don't parse ls

                                      – Zanna
                                      Sep 7 '17 at 15:15














                                    7












                                    7








                                    7







                                    Use this command:



                                    mv `ls|grep IDENTIFIER` /path/to/dest/folder  


                                    However, ls is not recommended for this kind of use. Use find command instead.






                                    share|improve this answer















                                    Use this command:



                                    mv `ls|grep IDENTIFIER` /path/to/dest/folder  


                                    However, ls is not recommended for this kind of use. Use find command instead.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 13 '12 at 18:18

























                                    answered Nov 8 '12 at 13:44









                                    igniteignite

                                    6,87232852




                                    6,87232852








                                    • 8





                                      ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                                      – NorTicUs
                                      Nov 8 '12 at 13:48











                                    • This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                                      – ignite
                                      Nov 8 '12 at 13:50






                                    • 3





                                      As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                                      – Paddy Landau
                                      Nov 13 '12 at 14:27











                                    • don't parse ls

                                      – Zanna
                                      Sep 7 '17 at 15:15














                                    • 8





                                      ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                                      – NorTicUs
                                      Nov 8 '12 at 13:48











                                    • This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                                      – ignite
                                      Nov 8 '12 at 13:50






                                    • 3





                                      As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                                      – Paddy Landau
                                      Nov 13 '12 at 14:27











                                    • don't parse ls

                                      – Zanna
                                      Sep 7 '17 at 15:15








                                    8




                                    8





                                    ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                                    – NorTicUs
                                    Nov 8 '12 at 13:48





                                    ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.

                                    – NorTicUs
                                    Nov 8 '12 at 13:48













                                    This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                                    – ignite
                                    Nov 8 '12 at 13:50





                                    This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.

                                    – ignite
                                    Nov 8 '12 at 13:50




                                    3




                                    3





                                    As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                                    – Paddy Landau
                                    Nov 13 '12 at 14:27





                                    As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.

                                    – Paddy Landau
                                    Nov 13 '12 at 14:27













                                    don't parse ls

                                    – Zanna
                                    Sep 7 '17 at 15:15





                                    don't parse ls

                                    – Zanna
                                    Sep 7 '17 at 15:15











                                    5














                                    If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:



                                    ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/


                                    The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.






                                    share|improve this answer
























                                    • This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                                      – AggieBill
                                      Nov 14 '12 at 10:11






                                    • 1





                                      +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                                      – Joe
                                      Nov 14 '12 at 23:33


















                                    5














                                    If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:



                                    ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/


                                    The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.






                                    share|improve this answer
























                                    • This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                                      – AggieBill
                                      Nov 14 '12 at 10:11






                                    • 1





                                      +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                                      – Joe
                                      Nov 14 '12 at 23:33
















                                    5












                                    5








                                    5







                                    If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:



                                    ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/


                                    The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.






                                    share|improve this answer













                                    If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:



                                    ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/


                                    The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 14 '12 at 10:05









                                    AggieBillAggieBill

                                    612




                                    612













                                    • This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                                      – AggieBill
                                      Nov 14 '12 at 10:11






                                    • 1





                                      +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                                      – Joe
                                      Nov 14 '12 at 23:33





















                                    • This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                                      – AggieBill
                                      Nov 14 '12 at 10:11






                                    • 1





                                      +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                                      – Joe
                                      Nov 14 '12 at 23:33



















                                    This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                                    – AggieBill
                                    Nov 14 '12 at 10:11





                                    This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.

                                    – AggieBill
                                    Nov 14 '12 at 10:11




                                    1




                                    1





                                    +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                                    – Joe
                                    Nov 14 '12 at 23:33







                                    +1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.

                                    – Joe
                                    Nov 14 '12 at 23:33













                                    5














                                    If the files are in the same dir you can use



                                    mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/


                                    (tested in Ubuntu 16.04)






                                    share|improve this answer





















                                    • 1





                                      This doesn't really add something to the existing answers, don't you think?

                                      – dessert
                                      Dec 1 '17 at 9:46






                                    • 1





                                      just eliminates the need to specify full path to dir for each file

                                      – Sruli
                                      Dec 1 '17 at 11:22


















                                    5














                                    If the files are in the same dir you can use



                                    mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/


                                    (tested in Ubuntu 16.04)






                                    share|improve this answer





















                                    • 1





                                      This doesn't really add something to the existing answers, don't you think?

                                      – dessert
                                      Dec 1 '17 at 9:46






                                    • 1





                                      just eliminates the need to specify full path to dir for each file

                                      – Sruli
                                      Dec 1 '17 at 11:22
















                                    5












                                    5








                                    5







                                    If the files are in the same dir you can use



                                    mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/


                                    (tested in Ubuntu 16.04)






                                    share|improve this answer















                                    If the files are in the same dir you can use



                                    mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/


                                    (tested in Ubuntu 16.04)







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Dec 1 '17 at 11:22

























                                    answered Dec 1 '17 at 9:19









                                    SruliSruli

                                    11614




                                    11614








                                    • 1





                                      This doesn't really add something to the existing answers, don't you think?

                                      – dessert
                                      Dec 1 '17 at 9:46






                                    • 1





                                      just eliminates the need to specify full path to dir for each file

                                      – Sruli
                                      Dec 1 '17 at 11:22
















                                    • 1





                                      This doesn't really add something to the existing answers, don't you think?

                                      – dessert
                                      Dec 1 '17 at 9:46






                                    • 1





                                      just eliminates the need to specify full path to dir for each file

                                      – Sruli
                                      Dec 1 '17 at 11:22










                                    1




                                    1





                                    This doesn't really add something to the existing answers, don't you think?

                                    – dessert
                                    Dec 1 '17 at 9:46





                                    This doesn't really add something to the existing answers, don't you think?

                                    – dessert
                                    Dec 1 '17 at 9:46




                                    1




                                    1





                                    just eliminates the need to specify full path to dir for each file

                                    – Sruli
                                    Dec 1 '17 at 11:22







                                    just eliminates the need to specify full path to dir for each file

                                    – Sruli
                                    Dec 1 '17 at 11:22













                                    3














                                    find -type f -name "[range]" -exec mv {} target-directory ';'


                                    this command will move file names with any pattern/range to target-directory.



                                    eg.



                                    find -type f -name "file[1-50000]" -exec mv {} target-directory ';'


                                    it will move files with names like file1, file2 ... file50000 to target-directory.






                                    share|improve this answer






























                                      3














                                      find -type f -name "[range]" -exec mv {} target-directory ';'


                                      this command will move file names with any pattern/range to target-directory.



                                      eg.



                                      find -type f -name "file[1-50000]" -exec mv {} target-directory ';'


                                      it will move files with names like file1, file2 ... file50000 to target-directory.






                                      share|improve this answer




























                                        3












                                        3








                                        3







                                        find -type f -name "[range]" -exec mv {} target-directory ';'


                                        this command will move file names with any pattern/range to target-directory.



                                        eg.



                                        find -type f -name "file[1-50000]" -exec mv {} target-directory ';'


                                        it will move files with names like file1, file2 ... file50000 to target-directory.






                                        share|improve this answer















                                        find -type f -name "[range]" -exec mv {} target-directory ';'


                                        this command will move file names with any pattern/range to target-directory.



                                        eg.



                                        find -type f -name "file[1-50000]" -exec mv {} target-directory ';'


                                        it will move files with names like file1, file2 ... file50000 to target-directory.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Sep 7 '17 at 15:12









                                        Zanna

                                        51.5k13141244




                                        51.5k13141244










                                        answered Sep 7 '17 at 14:51









                                        user734124user734124

                                        311




                                        311























                                            2














                                            You can use the output from ls to input into mv commnad



                                            mv $(ls | grep IDENTIFIER) /path/to/dest/dir



                                            The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.






                                            share|improve this answer



















                                            • 1





                                              don't parse ls

                                              – Zanna
                                              Sep 7 '17 at 15:14
















                                            2














                                            You can use the output from ls to input into mv commnad



                                            mv $(ls | grep IDENTIFIER) /path/to/dest/dir



                                            The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.






                                            share|improve this answer



















                                            • 1





                                              don't parse ls

                                              – Zanna
                                              Sep 7 '17 at 15:14














                                            2












                                            2








                                            2







                                            You can use the output from ls to input into mv commnad



                                            mv $(ls | grep IDENTIFIER) /path/to/dest/dir



                                            The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.






                                            share|improve this answer













                                            You can use the output from ls to input into mv commnad



                                            mv $(ls | grep IDENTIFIER) /path/to/dest/dir



                                            The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Nov 13 '12 at 19:38









                                            Fuad SaudFuad Saud

                                            1563




                                            1563








                                            • 1





                                              don't parse ls

                                              – Zanna
                                              Sep 7 '17 at 15:14














                                            • 1





                                              don't parse ls

                                              – Zanna
                                              Sep 7 '17 at 15:14








                                            1




                                            1





                                            don't parse ls

                                            – Zanna
                                            Sep 7 '17 at 15:14





                                            don't parse ls

                                            – Zanna
                                            Sep 7 '17 at 15:14











                                            1














                                            Using this command you can move multiple files.



                                            mv SourceFilenames ~DestinationPath






                                            share|improve this answer




























                                              1














                                              Using this command you can move multiple files.



                                              mv SourceFilenames ~DestinationPath






                                              share|improve this answer


























                                                1












                                                1








                                                1







                                                Using this command you can move multiple files.



                                                mv SourceFilenames ~DestinationPath






                                                share|improve this answer













                                                Using this command you can move multiple files.



                                                mv SourceFilenames ~DestinationPath







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 14 '12 at 10:13









                                                RajanandRajanand

                                                112




                                                112























                                                    1














                                                    Easiest way is like this



                                                    mv {file1,file2,file3} DESTINATION


                                                    or directory



                                                    mv {directory1,directory2,directory3} DESTINATION


                                                    or both files and directories



                                                    mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION


                                                    Hope this helps






                                                    share|improve this answer




























                                                      1














                                                      Easiest way is like this



                                                      mv {file1,file2,file3} DESTINATION


                                                      or directory



                                                      mv {directory1,directory2,directory3} DESTINATION


                                                      or both files and directories



                                                      mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION


                                                      Hope this helps






                                                      share|improve this answer


























                                                        1












                                                        1








                                                        1







                                                        Easiest way is like this



                                                        mv {file1,file2,file3} DESTINATION


                                                        or directory



                                                        mv {directory1,directory2,directory3} DESTINATION


                                                        or both files and directories



                                                        mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION


                                                        Hope this helps






                                                        share|improve this answer













                                                        Easiest way is like this



                                                        mv {file1,file2,file3} DESTINATION


                                                        or directory



                                                        mv {directory1,directory2,directory3} DESTINATION


                                                        or both files and directories



                                                        mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION


                                                        Hope this helps







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 6 '18 at 1:26









                                                        SabrinaSabrina

                                                        22618




                                                        22618






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Ask Ubuntu!


                                                            • 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%2faskubuntu.com%2fquestions%2f214560%2fhow-to-move-multiple-files-at-once-to-a-specific-destination-directory%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

                                                            Questions related to Moebius Transform of Characteristic Function of the Primes

                                                            List of scandals in India

                                                            Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?