move file by list in file (with leading whitespace)

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











up vote
8
down vote

favorite
7












I have a file that contains file names. For example:



/tmp/list.txt (it is with the spaces at the start of each line):



 /tmp/file.log
/app/nir/home.txt
/etc/config.cust


I want, using one line, to move all the files listed in /tmp/list.txt to /app/dest



So it should be something like this:



cat /tmp/list.txt | xargs mv /app/dest/






share|improve this question


























    up vote
    8
    down vote

    favorite
    7












    I have a file that contains file names. For example:



    /tmp/list.txt (it is with the spaces at the start of each line):



     /tmp/file.log
    /app/nir/home.txt
    /etc/config.cust


    I want, using one line, to move all the files listed in /tmp/list.txt to /app/dest



    So it should be something like this:



    cat /tmp/list.txt | xargs mv /app/dest/






    share|improve this question
























      up vote
      8
      down vote

      favorite
      7









      up vote
      8
      down vote

      favorite
      7






      7





      I have a file that contains file names. For example:



      /tmp/list.txt (it is with the spaces at the start of each line):



       /tmp/file.log
      /app/nir/home.txt
      /etc/config.cust


      I want, using one line, to move all the files listed in /tmp/list.txt to /app/dest



      So it should be something like this:



      cat /tmp/list.txt | xargs mv /app/dest/






      share|improve this question














      I have a file that contains file names. For example:



      /tmp/list.txt (it is with the spaces at the start of each line):



       /tmp/file.log
      /app/nir/home.txt
      /etc/config.cust


      I want, using one line, to move all the files listed in /tmp/list.txt to /app/dest



      So it should be something like this:



      cat /tmp/list.txt | xargs mv /app/dest/








      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 17 '17 at 10:37









      roaima

      39.5k545107




      39.5k545107










      asked Feb 18 '14 at 15:38









      Nir

      40121019




      40121019




















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          16
          down vote



          accepted










          You are just missing the -t option for mv (assuming GNU mv):



          cat /tmp/list.txt | xargs mv -t /app/dest/


          or shorter (inspired by X Tian's answer):



          xargs mv -t /app/dest/ < /tmp/list.txt


          the leading (and possible trailing) spaces are removed. Spaces within the filenames will lead to problems.



          If you have spaces or tabs or quotes or backslashes in the filenames, assuming GNU xargs you can use:



          sed 's/^ *//' < /tmp/list.txt | xargs -d 'n' mv -t /app/dest/





          share|improve this answer






















          • Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
            – inukaze
            Feb 14 '16 at 16:49


















          up vote
          6
          down vote













          Assuming your file names are relatively sane (no newlines or weird characters):



          while read file; do mv "$file" /app/dest/; done < list.txt 


          To deal with weird file names (breaks if a file name has a newline):



          while IFS= read -r file; do mv "$file" /app/dest/; done < list.txt 





          share|improve this answer




















          • Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
            – user3351523
            Mar 26 at 9:59











          • @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
            – terdon♦
            Mar 26 at 11:23










          • I did that. you can have a look.
            – user3351523
            Mar 26 at 11:30










          • @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
            – terdon♦
            Mar 26 at 11:41

















          up vote
          3
          down vote













          for i in $(cat /tmp/list.txt); do mv "$i" /app/dest/; done





          share|improve this answer





























            up vote
            1
            down vote













            Pure xargs reading directly from file



            xargs -l -i < flist mv -v /app/dst


            edit 1 -- after @Anthon 's comment below,



            xargs -I < flist mv -v /app/dst





            share|improve this answer


















            • 1




              -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
              – Anthon
              Feb 18 '14 at 16:24

















            up vote
            0
            down vote













            mv `cat /tmp/list.txt` /app/dest/


            (spaces at start are ignored)






            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );








               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f115734%2fmove-file-by-list-in-file-with-leading-whitespace%23new-answer', 'question_page');

              );

              Post as a guest






























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              16
              down vote



              accepted










              You are just missing the -t option for mv (assuming GNU mv):



              cat /tmp/list.txt | xargs mv -t /app/dest/


              or shorter (inspired by X Tian's answer):



              xargs mv -t /app/dest/ < /tmp/list.txt


              the leading (and possible trailing) spaces are removed. Spaces within the filenames will lead to problems.



              If you have spaces or tabs or quotes or backslashes in the filenames, assuming GNU xargs you can use:



              sed 's/^ *//' < /tmp/list.txt | xargs -d 'n' mv -t /app/dest/





              share|improve this answer






















              • Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
                – inukaze
                Feb 14 '16 at 16:49















              up vote
              16
              down vote



              accepted










              You are just missing the -t option for mv (assuming GNU mv):



              cat /tmp/list.txt | xargs mv -t /app/dest/


              or shorter (inspired by X Tian's answer):



              xargs mv -t /app/dest/ < /tmp/list.txt


              the leading (and possible trailing) spaces are removed. Spaces within the filenames will lead to problems.



              If you have spaces or tabs or quotes or backslashes in the filenames, assuming GNU xargs you can use:



              sed 's/^ *//' < /tmp/list.txt | xargs -d 'n' mv -t /app/dest/





              share|improve this answer






















              • Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
                – inukaze
                Feb 14 '16 at 16:49













              up vote
              16
              down vote



              accepted







              up vote
              16
              down vote



              accepted






              You are just missing the -t option for mv (assuming GNU mv):



              cat /tmp/list.txt | xargs mv -t /app/dest/


              or shorter (inspired by X Tian's answer):



              xargs mv -t /app/dest/ < /tmp/list.txt


              the leading (and possible trailing) spaces are removed. Spaces within the filenames will lead to problems.



              If you have spaces or tabs or quotes or backslashes in the filenames, assuming GNU xargs you can use:



              sed 's/^ *//' < /tmp/list.txt | xargs -d 'n' mv -t /app/dest/





              share|improve this answer














              You are just missing the -t option for mv (assuming GNU mv):



              cat /tmp/list.txt | xargs mv -t /app/dest/


              or shorter (inspired by X Tian's answer):



              xargs mv -t /app/dest/ < /tmp/list.txt


              the leading (and possible trailing) spaces are removed. Spaces within the filenames will lead to problems.



              If you have spaces or tabs or quotes or backslashes in the filenames, assuming GNU xargs you can use:



              sed 's/^ *//' < /tmp/list.txt | xargs -d 'n' mv -t /app/dest/






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Feb 18 '14 at 19:32









              Stéphane Chazelas

              280k53514846




              280k53514846










              answered Feb 18 '14 at 15:48









              Anthon

              58.3k1795157




              58.3k1795157











              • Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
                – inukaze
                Feb 14 '16 at 16:49

















              • Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
                – inukaze
                Feb 14 '16 at 16:49
















              Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
              – inukaze
              Feb 14 '16 at 16:49





              Thank you , for the answer . with this i can make a list of lot of files with [!] in their name , and move to another folder , with the follow : ls | grep -e ".[!]]" | tee 001.txt ; sed 's/^ *//' < 001.txt | xargs -d 'n' mv -t /destinypath/
              – inukaze
              Feb 14 '16 at 16:49













              up vote
              6
              down vote













              Assuming your file names are relatively sane (no newlines or weird characters):



              while read file; do mv "$file" /app/dest/; done < list.txt 


              To deal with weird file names (breaks if a file name has a newline):



              while IFS= read -r file; do mv "$file" /app/dest/; done < list.txt 





              share|improve this answer




















              • Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
                – user3351523
                Mar 26 at 9:59











              • @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
                – terdon♦
                Mar 26 at 11:23










              • I did that. you can have a look.
                – user3351523
                Mar 26 at 11:30










              • @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
                – terdon♦
                Mar 26 at 11:41














              up vote
              6
              down vote













              Assuming your file names are relatively sane (no newlines or weird characters):



              while read file; do mv "$file" /app/dest/; done < list.txt 


              To deal with weird file names (breaks if a file name has a newline):



              while IFS= read -r file; do mv "$file" /app/dest/; done < list.txt 





              share|improve this answer




















              • Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
                – user3351523
                Mar 26 at 9:59











              • @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
                – terdon♦
                Mar 26 at 11:23










              • I did that. you can have a look.
                – user3351523
                Mar 26 at 11:30










              • @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
                – terdon♦
                Mar 26 at 11:41












              up vote
              6
              down vote










              up vote
              6
              down vote









              Assuming your file names are relatively sane (no newlines or weird characters):



              while read file; do mv "$file" /app/dest/; done < list.txt 


              To deal with weird file names (breaks if a file name has a newline):



              while IFS= read -r file; do mv "$file" /app/dest/; done < list.txt 





              share|improve this answer












              Assuming your file names are relatively sane (no newlines or weird characters):



              while read file; do mv "$file" /app/dest/; done < list.txt 


              To deal with weird file names (breaks if a file name has a newline):



              while IFS= read -r file; do mv "$file" /app/dest/; done < list.txt 






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 18 '14 at 15:50









              terdon♦

              122k28229400




              122k28229400











              • Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
                – user3351523
                Mar 26 at 9:59











              • @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
                – terdon♦
                Mar 26 at 11:23










              • I did that. you can have a look.
                – user3351523
                Mar 26 at 11:30










              • @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
                – terdon♦
                Mar 26 at 11:41
















              • Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
                – user3351523
                Mar 26 at 9:59











              • @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
                – terdon♦
                Mar 26 at 11:23










              • I did that. you can have a look.
                – user3351523
                Mar 26 at 11:30










              • @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
                – terdon♦
                Mar 26 at 11:41















              Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
              – user3351523
              Mar 26 at 9:59





              Hi terdon, how to move folders into new directory based on their match in the csv file? Could you please help me with this [unix.stackexchange.com/questions/433068/… Thank you !!
              – user3351523
              Mar 26 at 9:59













              @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
              – terdon♦
              Mar 26 at 11:23




              @user3351523 your question has been closed. Asking random people for help won't change that. Instead, edit the question, and explain how the solutions in the duplicate didn't help you. If something "didn't work", explain how it failed. The solutions should work for you, so you need to explain what happens when you try them.
              – terdon♦
              Mar 26 at 11:23












              I did that. you can have a look.
              – user3351523
              Mar 26 at 11:30




              I did that. you can have a look.
              – user3351523
              Mar 26 at 11:30












              @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
              – terdon♦
              Mar 26 at 11:41




              @user3351523 you haven't explained why the solutions of the dupe fail for you. And you haven't explained how the answers you have gotten fail. You might just need to use cp -Hr but I don't know if OSX cp supports that.
              – terdon♦
              Mar 26 at 11:41










              up vote
              3
              down vote













              for i in $(cat /tmp/list.txt); do mv "$i" /app/dest/; done





              share|improve this answer


























                up vote
                3
                down vote













                for i in $(cat /tmp/list.txt); do mv "$i" /app/dest/; done





                share|improve this answer
























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  for i in $(cat /tmp/list.txt); do mv "$i" /app/dest/; done





                  share|improve this answer














                  for i in $(cat /tmp/list.txt); do mv "$i" /app/dest/; done






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 18 '14 at 15:48









                  terdon♦

                  122k28229400




                  122k28229400










                  answered Feb 18 '14 at 15:46









                  mavillan

                  1,38941425




                  1,38941425




















                      up vote
                      1
                      down vote













                      Pure xargs reading directly from file



                      xargs -l -i < flist mv -v /app/dst


                      edit 1 -- after @Anthon 's comment below,



                      xargs -I < flist mv -v /app/dst





                      share|improve this answer


















                      • 1




                        -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
                        – Anthon
                        Feb 18 '14 at 16:24














                      up vote
                      1
                      down vote













                      Pure xargs reading directly from file



                      xargs -l -i < flist mv -v /app/dst


                      edit 1 -- after @Anthon 's comment below,



                      xargs -I < flist mv -v /app/dst





                      share|improve this answer


















                      • 1




                        -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
                        – Anthon
                        Feb 18 '14 at 16:24












                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      Pure xargs reading directly from file



                      xargs -l -i < flist mv -v /app/dst


                      edit 1 -- after @Anthon 's comment below,



                      xargs -I < flist mv -v /app/dst





                      share|improve this answer














                      Pure xargs reading directly from file



                      xargs -l -i < flist mv -v /app/dst


                      edit 1 -- after @Anthon 's comment below,



                      xargs -I < flist mv -v /app/dst






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 18 '14 at 16:29

























                      answered Feb 18 '14 at 15:54









                      X Tian

                      7,29111836




                      7,29111836







                      • 1




                        -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
                        – Anthon
                        Feb 18 '14 at 16:24












                      • 1




                        -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
                        – Anthon
                        Feb 18 '14 at 16:24







                      1




                      1




                      -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
                      – Anthon
                      Feb 18 '14 at 16:24




                      -i is deprecrated, and it, or it replacement -I imply -l/--max-lines=1. And it causes mv to be executed for each file separately.
                      – Anthon
                      Feb 18 '14 at 16:24










                      up vote
                      0
                      down vote













                      mv `cat /tmp/list.txt` /app/dest/


                      (spaces at start are ignored)






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        mv `cat /tmp/list.txt` /app/dest/


                        (spaces at start are ignored)






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          mv `cat /tmp/list.txt` /app/dest/


                          (spaces at start are ignored)






                          share|improve this answer












                          mv `cat /tmp/list.txt` /app/dest/


                          (spaces at start are ignored)







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 19 '15 at 1:56









                          Espen Mikal Robertsen

                          11




                          11






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f115734%2fmove-file-by-list-in-file-with-leading-whitespace%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?