Copy files from one folder to another folder within specific date range

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











up vote
4
down vote

favorite
1












I am already using below command to copy files from a specific date.



Previously I used this command and it worked well but now it was showing an error:



-bash: /bin/cp: Argument list too long


Commends used:



cd /share/new/
cp `find . -type f -newermt '16 july 2018'` /share/test


I need to copy all files in the folder "new" from July 20th to today date. How can I achieve this?










share|improve this question



























    up vote
    4
    down vote

    favorite
    1












    I am already using below command to copy files from a specific date.



    Previously I used this command and it worked well but now it was showing an error:



    -bash: /bin/cp: Argument list too long


    Commends used:



    cd /share/new/
    cp `find . -type f -newermt '16 july 2018'` /share/test


    I need to copy all files in the folder "new" from July 20th to today date. How can I achieve this?










    share|improve this question

























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      I am already using below command to copy files from a specific date.



      Previously I used this command and it worked well but now it was showing an error:



      -bash: /bin/cp: Argument list too long


      Commends used:



      cd /share/new/
      cp `find . -type f -newermt '16 july 2018'` /share/test


      I need to copy all files in the folder "new" from July 20th to today date. How can I achieve this?










      share|improve this question















      I am already using below command to copy files from a specific date.



      Previously I used this command and it worked well but now it was showing an error:



      -bash: /bin/cp: Argument list too long


      Commends used:



      cd /share/new/
      cp `find . -type f -newermt '16 july 2018'` /share/test


      I need to copy all files in the folder "new" from July 20th to today date. How can I achieve this?







      command-line bash copy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 25 at 9:08









      Videonauth

      22.6k116898




      22.6k116898










      asked Sep 25 at 9:05









      Venki

      305




      305




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          9
          down vote



          accepted










          Don't use cp directly with the output of find.



          It might passes way many too files in a single step (and that's why you get the error Argument list too long).



          Use the -exec parameter of find, which execute the given command passing a every matched file to cp, one at a time:



          cd /share/new/
          find . -type f -newermt '16 july 2018' -exec cp /share/test ;





          share|improve this answer


















          • 1




            its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
            – Venki
            Sep 25 at 9:26







          • 1




            I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
            – vanadium
            Sep 25 at 10:22






          • 4




            @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
            – Ian Emnace
            Sep 25 at 17:51






          • 3




            You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
            – Zanna
            Sep 25 at 17:58







          • 1




            @IanEmnace Thank! Removed the quotes again, not needed indeed!
            – vanadium
            Sep 25 at 18:36

















          up vote
          3
          down vote













          use find -exec:



          find /share/new/ -type f -newermt '16 july 2018' -exec cp /share/test ;





          share|improve this answer




















          • getting same error for your command also find: missing argument to `-exec'
            – Venki
            Sep 25 at 9:18











          • I think your missing the ; at the end.
            – RoVo
            Sep 25 at 9:20











          • test is a directory i am missing / after test
            – Venki
            Sep 25 at 9:31

















          up vote
          0
          down vote













          Make use of the -exec action of find and the -t option of cp; I also recommend the -i or -n options if you don’t want to overwrite identically named files by accident:



          find ... -exec cp -i -t TARGET -- +


          The other current answers spawn a cp child process for every matching file while this answer only spawns as many as necessary based on the total program argument length limit (see below) which will make a big difference once you reach a couple of thousand matches which appears to be your case.




          From the find(1) manual:




          • -exec command ; – Execute command […]. All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered. The string is replaced by the current file name being processed everywhere it occurs in the arguments to the command […]. The specified command is run once for each matched file. […]


          • -exec command + – This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. […]




          From the cp(1) manual:





          • -t, --target-directory=DIRECTORY – copy all SOURCE arguments into DIRECTORY


          • -i, --interactive – prompt before overwrite


          • -n, --no-clobber – do not overwrite an existing file






          share|improve this answer





























            up vote
            -1
            down vote













            You should try this syntax:



            find /share/new/ -type f -newermt '16 july 2018' -exec cp -R /share/test/ ;





            share|improve this answer


















            • 2




              What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
              – PerlDuck
              Sep 25 at 18:12










            • Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
              – PerlDuck
              Sep 26 at 8:33










            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',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1078245%2fcopy-files-from-one-folder-to-another-folder-within-specific-date-range%23new-answer', 'question_page');

            );

            Post as a guest






























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            9
            down vote



            accepted










            Don't use cp directly with the output of find.



            It might passes way many too files in a single step (and that's why you get the error Argument list too long).



            Use the -exec parameter of find, which execute the given command passing a every matched file to cp, one at a time:



            cd /share/new/
            find . -type f -newermt '16 july 2018' -exec cp /share/test ;





            share|improve this answer


















            • 1




              its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
              – Venki
              Sep 25 at 9:26







            • 1




              I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
              – vanadium
              Sep 25 at 10:22






            • 4




              @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
              – Ian Emnace
              Sep 25 at 17:51






            • 3




              You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
              – Zanna
              Sep 25 at 17:58







            • 1




              @IanEmnace Thank! Removed the quotes again, not needed indeed!
              – vanadium
              Sep 25 at 18:36














            up vote
            9
            down vote



            accepted










            Don't use cp directly with the output of find.



            It might passes way many too files in a single step (and that's why you get the error Argument list too long).



            Use the -exec parameter of find, which execute the given command passing a every matched file to cp, one at a time:



            cd /share/new/
            find . -type f -newermt '16 july 2018' -exec cp /share/test ;





            share|improve this answer


















            • 1




              its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
              – Venki
              Sep 25 at 9:26







            • 1




              I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
              – vanadium
              Sep 25 at 10:22






            • 4




              @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
              – Ian Emnace
              Sep 25 at 17:51






            • 3




              You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
              – Zanna
              Sep 25 at 17:58







            • 1




              @IanEmnace Thank! Removed the quotes again, not needed indeed!
              – vanadium
              Sep 25 at 18:36












            up vote
            9
            down vote



            accepted







            up vote
            9
            down vote



            accepted






            Don't use cp directly with the output of find.



            It might passes way many too files in a single step (and that's why you get the error Argument list too long).



            Use the -exec parameter of find, which execute the given command passing a every matched file to cp, one at a time:



            cd /share/new/
            find . -type f -newermt '16 july 2018' -exec cp /share/test ;





            share|improve this answer














            Don't use cp directly with the output of find.



            It might passes way many too files in a single step (and that's why you get the error Argument list too long).



            Use the -exec parameter of find, which execute the given command passing a every matched file to cp, one at a time:



            cd /share/new/
            find . -type f -newermt '16 july 2018' -exec cp /share/test ;






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 25 at 18:35









            vanadium

            2,5641721




            2,5641721










            answered Sep 25 at 9:11









            Mr Shunz

            2,1121320




            2,1121320







            • 1




              its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
              – Venki
              Sep 25 at 9:26







            • 1




              I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
              – vanadium
              Sep 25 at 10:22






            • 4




              @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
              – Ian Emnace
              Sep 25 at 17:51






            • 3




              You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
              – Zanna
              Sep 25 at 17:58







            • 1




              @IanEmnace Thank! Removed the quotes again, not needed indeed!
              – vanadium
              Sep 25 at 18:36












            • 1




              its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
              – Venki
              Sep 25 at 9:26







            • 1




              I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
              – vanadium
              Sep 25 at 10:22






            • 4




              @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
              – Ian Emnace
              Sep 25 at 17:51






            • 3




              You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
              – Zanna
              Sep 25 at 17:58







            • 1




              @IanEmnace Thank! Removed the quotes again, not needed indeed!
              – vanadium
              Sep 25 at 18:36







            1




            1




            its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
            – Venki
            Sep 25 at 9:26





            its working :: "" find . -type f -newermt '16 july 2018' -exec cp /share/test/ ; "" missing "/" after test because test is a directory
            – Venki
            Sep 25 at 9:26





            1




            1




            I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
            – vanadium
            Sep 25 at 10:22




            I added quotes to the "". This will make sure files with names containing spaces are handled correctly.
            – vanadium
            Sep 25 at 10:22




            4




            4




            @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
            – Ian Emnace
            Sep 25 at 17:51




            @vanadium find's -exec executes the program directly. It doesn't invoke a shell; is replaced with the filename as a single argument regardless of quoting (which find never actually sees, anyway).
            – Ian Emnace
            Sep 25 at 17:51




            3




            3




            You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
            – Zanna
            Sep 25 at 17:58





            You can improve the efficiency of this command (which probably matters if OP is getting "argument list too long") by specifying the destination explicitly with the -t switch, rather than by syntax, and making use of + which constructs an argument list, ie find <tests> -exec cp -t /share/test + The argument list is broken as many times as needed to complete without exceeding the limit. This avoids launching cp n times where n is the number of files...
            – Zanna
            Sep 25 at 17:58





            1




            1




            @IanEmnace Thank! Removed the quotes again, not needed indeed!
            – vanadium
            Sep 25 at 18:36




            @IanEmnace Thank! Removed the quotes again, not needed indeed!
            – vanadium
            Sep 25 at 18:36












            up vote
            3
            down vote













            use find -exec:



            find /share/new/ -type f -newermt '16 july 2018' -exec cp /share/test ;





            share|improve this answer




















            • getting same error for your command also find: missing argument to `-exec'
              – Venki
              Sep 25 at 9:18











            • I think your missing the ; at the end.
              – RoVo
              Sep 25 at 9:20











            • test is a directory i am missing / after test
              – Venki
              Sep 25 at 9:31














            up vote
            3
            down vote













            use find -exec:



            find /share/new/ -type f -newermt '16 july 2018' -exec cp /share/test ;





            share|improve this answer




















            • getting same error for your command also find: missing argument to `-exec'
              – Venki
              Sep 25 at 9:18











            • I think your missing the ; at the end.
              – RoVo
              Sep 25 at 9:20











            • test is a directory i am missing / after test
              – Venki
              Sep 25 at 9:31












            up vote
            3
            down vote










            up vote
            3
            down vote









            use find -exec:



            find /share/new/ -type f -newermt '16 july 2018' -exec cp /share/test ;





            share|improve this answer












            use find -exec:



            find /share/new/ -type f -newermt '16 july 2018' -exec cp /share/test ;






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 25 at 9:09









            RoVo

            5,8391438




            5,8391438











            • getting same error for your command also find: missing argument to `-exec'
              – Venki
              Sep 25 at 9:18











            • I think your missing the ; at the end.
              – RoVo
              Sep 25 at 9:20











            • test is a directory i am missing / after test
              – Venki
              Sep 25 at 9:31
















            • getting same error for your command also find: missing argument to `-exec'
              – Venki
              Sep 25 at 9:18











            • I think your missing the ; at the end.
              – RoVo
              Sep 25 at 9:20











            • test is a directory i am missing / after test
              – Venki
              Sep 25 at 9:31















            getting same error for your command also find: missing argument to `-exec'
            – Venki
            Sep 25 at 9:18





            getting same error for your command also find: missing argument to `-exec'
            – Venki
            Sep 25 at 9:18













            I think your missing the ; at the end.
            – RoVo
            Sep 25 at 9:20





            I think your missing the ; at the end.
            – RoVo
            Sep 25 at 9:20













            test is a directory i am missing / after test
            – Venki
            Sep 25 at 9:31




            test is a directory i am missing / after test
            – Venki
            Sep 25 at 9:31










            up vote
            0
            down vote













            Make use of the -exec action of find and the -t option of cp; I also recommend the -i or -n options if you don’t want to overwrite identically named files by accident:



            find ... -exec cp -i -t TARGET -- +


            The other current answers spawn a cp child process for every matching file while this answer only spawns as many as necessary based on the total program argument length limit (see below) which will make a big difference once you reach a couple of thousand matches which appears to be your case.




            From the find(1) manual:




            • -exec command ; – Execute command […]. All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered. The string is replaced by the current file name being processed everywhere it occurs in the arguments to the command […]. The specified command is run once for each matched file. […]


            • -exec command + – This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. […]




            From the cp(1) manual:





            • -t, --target-directory=DIRECTORY – copy all SOURCE arguments into DIRECTORY


            • -i, --interactive – prompt before overwrite


            • -n, --no-clobber – do not overwrite an existing file






            share|improve this answer


























              up vote
              0
              down vote













              Make use of the -exec action of find and the -t option of cp; I also recommend the -i or -n options if you don’t want to overwrite identically named files by accident:



              find ... -exec cp -i -t TARGET -- +


              The other current answers spawn a cp child process for every matching file while this answer only spawns as many as necessary based on the total program argument length limit (see below) which will make a big difference once you reach a couple of thousand matches which appears to be your case.




              From the find(1) manual:




              • -exec command ; – Execute command […]. All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered. The string is replaced by the current file name being processed everywhere it occurs in the arguments to the command […]. The specified command is run once for each matched file. […]


              • -exec command + – This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. […]




              From the cp(1) manual:





              • -t, --target-directory=DIRECTORY – copy all SOURCE arguments into DIRECTORY


              • -i, --interactive – prompt before overwrite


              • -n, --no-clobber – do not overwrite an existing file






              share|improve this answer
























                up vote
                0
                down vote










                up vote
                0
                down vote









                Make use of the -exec action of find and the -t option of cp; I also recommend the -i or -n options if you don’t want to overwrite identically named files by accident:



                find ... -exec cp -i -t TARGET -- +


                The other current answers spawn a cp child process for every matching file while this answer only spawns as many as necessary based on the total program argument length limit (see below) which will make a big difference once you reach a couple of thousand matches which appears to be your case.




                From the find(1) manual:




                • -exec command ; – Execute command […]. All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered. The string is replaced by the current file name being processed everywhere it occurs in the arguments to the command […]. The specified command is run once for each matched file. […]


                • -exec command + – This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. […]




                From the cp(1) manual:





                • -t, --target-directory=DIRECTORY – copy all SOURCE arguments into DIRECTORY


                • -i, --interactive – prompt before overwrite


                • -n, --no-clobber – do not overwrite an existing file






                share|improve this answer














                Make use of the -exec action of find and the -t option of cp; I also recommend the -i or -n options if you don’t want to overwrite identically named files by accident:



                find ... -exec cp -i -t TARGET -- +


                The other current answers spawn a cp child process for every matching file while this answer only spawns as many as necessary based on the total program argument length limit (see below) which will make a big difference once you reach a couple of thousand matches which appears to be your case.




                From the find(1) manual:




                • -exec command ; – Execute command […]. All following arguments to find are taken to be arguments to the command until an argument consisting of ; is encountered. The string is replaced by the current file name being processed everywhere it occurs in the arguments to the command […]. The specified command is run once for each matched file. […]


                • -exec command + – This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. […]




                From the cp(1) manual:





                • -t, --target-directory=DIRECTORY – copy all SOURCE arguments into DIRECTORY


                • -i, --interactive – prompt before overwrite


                • -n, --no-clobber – do not overwrite an existing file







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Sep 26 at 2:19

























                answered Sep 26 at 2:13









                David Foerster

                26.6k1363106




                26.6k1363106




















                    up vote
                    -1
                    down vote













                    You should try this syntax:



                    find /share/new/ -type f -newermt '16 july 2018' -exec cp -R /share/test/ ;





                    share|improve this answer


















                    • 2




                      What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
                      – PerlDuck
                      Sep 25 at 18:12










                    • Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
                      – PerlDuck
                      Sep 26 at 8:33














                    up vote
                    -1
                    down vote













                    You should try this syntax:



                    find /share/new/ -type f -newermt '16 july 2018' -exec cp -R /share/test/ ;





                    share|improve this answer


















                    • 2




                      What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
                      – PerlDuck
                      Sep 25 at 18:12










                    • Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
                      – PerlDuck
                      Sep 26 at 8:33












                    up vote
                    -1
                    down vote










                    up vote
                    -1
                    down vote









                    You should try this syntax:



                    find /share/new/ -type f -newermt '16 july 2018' -exec cp -R /share/test/ ;





                    share|improve this answer














                    You should try this syntax:



                    find /share/new/ -type f -newermt '16 july 2018' -exec cp -R /share/test/ ;






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Sep 25 at 18:01









                    Zanna

                    48.3k13120229




                    48.3k13120229










                    answered Sep 25 at 11:36









                    Rehan

                    73




                    73







                    • 2




                      What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
                      – PerlDuck
                      Sep 25 at 18:12










                    • Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
                      – PerlDuck
                      Sep 26 at 8:33












                    • 2




                      What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
                      – PerlDuck
                      Sep 25 at 18:12










                    • Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
                      – PerlDuck
                      Sep 26 at 8:33







                    2




                    2




                    What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
                    – PerlDuck
                    Sep 25 at 18:12




                    What is the purpose of the -R here? Doesn't it recursively copy /share/test to all the files found? That seems wrong.
                    – PerlDuck
                    Sep 25 at 18:12












                    Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
                    – PerlDuck
                    Sep 26 at 8:33




                    Well, no. The OP wants to copy a $source_file to a $target_directory. The command you propose instead recursively copies the $target_directory to the $source_file. This doesn't make sense. Not only the direction is just the other way round, but also when copying recursively, the target must be a directory, not a file. When we run cp -R /source/directory /target/file then we get cp: cannot overwrite non-directory 'target/file' with directory '/source/directory'.
                    – PerlDuck
                    Sep 26 at 8:33

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1078245%2fcopy-files-from-one-folder-to-another-folder-within-specific-date-range%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?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay