copy two files at a time





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







6















What to do if I want to copy two file at a time using command ? let's say I have one folder named ABC and files are



mno.txt
xyz.txt
abcd.txt
qwe.txt and so on (100 no. of files)


Now I want to cp mno.txt and xyz.txt at a time . How can I do this ?










share|improve this question























  • Copy to where? To ABC?

    – Carsten S
    Oct 18 '16 at 7:29











  • To different folder .

    – Avani badheka
    Oct 18 '16 at 7:37






  • 2





    Assuming that you actually want to copy several files at the same time, and not just after each other, could you say something about the reason why you want to do this? If it is to improve performance, it probably will not work.

    – Thomas Padron-McCarthy
    Oct 18 '16 at 7:46











  • My aim is to make my work speedy.I am dealing with asterisk and while making config files cp generally I have only two files to give attention.So every time I seperatly copy that two files.So I want that two files at another latest folder at a time only for saving time , else separately cp of that two files is my current scenario.

    – Avani badheka
    Oct 18 '16 at 8:08






  • 1





    If the filesystem is sitting on a spinning platter hd (instead of ssd) then copying sequentially will be faster as the heads won't need to seek between the two different source and destination files. If on a RAID then things are more complicated as the files can be on (or even split over) several drives.

    – Rycochet
    Oct 18 '16 at 8:45


















6















What to do if I want to copy two file at a time using command ? let's say I have one folder named ABC and files are



mno.txt
xyz.txt
abcd.txt
qwe.txt and so on (100 no. of files)


Now I want to cp mno.txt and xyz.txt at a time . How can I do this ?










share|improve this question























  • Copy to where? To ABC?

    – Carsten S
    Oct 18 '16 at 7:29











  • To different folder .

    – Avani badheka
    Oct 18 '16 at 7:37






  • 2





    Assuming that you actually want to copy several files at the same time, and not just after each other, could you say something about the reason why you want to do this? If it is to improve performance, it probably will not work.

    – Thomas Padron-McCarthy
    Oct 18 '16 at 7:46











  • My aim is to make my work speedy.I am dealing with asterisk and while making config files cp generally I have only two files to give attention.So every time I seperatly copy that two files.So I want that two files at another latest folder at a time only for saving time , else separately cp of that two files is my current scenario.

    – Avani badheka
    Oct 18 '16 at 8:08






  • 1





    If the filesystem is sitting on a spinning platter hd (instead of ssd) then copying sequentially will be faster as the heads won't need to seek between the two different source and destination files. If on a RAID then things are more complicated as the files can be on (or even split over) several drives.

    – Rycochet
    Oct 18 '16 at 8:45














6












6








6


1






What to do if I want to copy two file at a time using command ? let's say I have one folder named ABC and files are



mno.txt
xyz.txt
abcd.txt
qwe.txt and so on (100 no. of files)


Now I want to cp mno.txt and xyz.txt at a time . How can I do this ?










share|improve this question














What to do if I want to copy two file at a time using command ? let's say I have one folder named ABC and files are



mno.txt
xyz.txt
abcd.txt
qwe.txt and so on (100 no. of files)


Now I want to cp mno.txt and xyz.txt at a time . How can I do this ?







command-line files cp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 18 '16 at 6:47









Avani badhekaAvani badheka

1,0414929




1,0414929













  • Copy to where? To ABC?

    – Carsten S
    Oct 18 '16 at 7:29











  • To different folder .

    – Avani badheka
    Oct 18 '16 at 7:37






  • 2





    Assuming that you actually want to copy several files at the same time, and not just after each other, could you say something about the reason why you want to do this? If it is to improve performance, it probably will not work.

    – Thomas Padron-McCarthy
    Oct 18 '16 at 7:46











  • My aim is to make my work speedy.I am dealing with asterisk and while making config files cp generally I have only two files to give attention.So every time I seperatly copy that two files.So I want that two files at another latest folder at a time only for saving time , else separately cp of that two files is my current scenario.

    – Avani badheka
    Oct 18 '16 at 8:08






  • 1





    If the filesystem is sitting on a spinning platter hd (instead of ssd) then copying sequentially will be faster as the heads won't need to seek between the two different source and destination files. If on a RAID then things are more complicated as the files can be on (or even split over) several drives.

    – Rycochet
    Oct 18 '16 at 8:45



















  • Copy to where? To ABC?

    – Carsten S
    Oct 18 '16 at 7:29











  • To different folder .

    – Avani badheka
    Oct 18 '16 at 7:37






  • 2





    Assuming that you actually want to copy several files at the same time, and not just after each other, could you say something about the reason why you want to do this? If it is to improve performance, it probably will not work.

    – Thomas Padron-McCarthy
    Oct 18 '16 at 7:46











  • My aim is to make my work speedy.I am dealing with asterisk and while making config files cp generally I have only two files to give attention.So every time I seperatly copy that two files.So I want that two files at another latest folder at a time only for saving time , else separately cp of that two files is my current scenario.

    – Avani badheka
    Oct 18 '16 at 8:08






  • 1





    If the filesystem is sitting on a spinning platter hd (instead of ssd) then copying sequentially will be faster as the heads won't need to seek between the two different source and destination files. If on a RAID then things are more complicated as the files can be on (or even split over) several drives.

    – Rycochet
    Oct 18 '16 at 8:45

















Copy to where? To ABC?

– Carsten S
Oct 18 '16 at 7:29





Copy to where? To ABC?

– Carsten S
Oct 18 '16 at 7:29













To different folder .

– Avani badheka
Oct 18 '16 at 7:37





To different folder .

– Avani badheka
Oct 18 '16 at 7:37




2




2





Assuming that you actually want to copy several files at the same time, and not just after each other, could you say something about the reason why you want to do this? If it is to improve performance, it probably will not work.

– Thomas Padron-McCarthy
Oct 18 '16 at 7:46





Assuming that you actually want to copy several files at the same time, and not just after each other, could you say something about the reason why you want to do this? If it is to improve performance, it probably will not work.

– Thomas Padron-McCarthy
Oct 18 '16 at 7:46













My aim is to make my work speedy.I am dealing with asterisk and while making config files cp generally I have only two files to give attention.So every time I seperatly copy that two files.So I want that two files at another latest folder at a time only for saving time , else separately cp of that two files is my current scenario.

– Avani badheka
Oct 18 '16 at 8:08





My aim is to make my work speedy.I am dealing with asterisk and while making config files cp generally I have only two files to give attention.So every time I seperatly copy that two files.So I want that two files at another latest folder at a time only for saving time , else separately cp of that two files is my current scenario.

– Avani badheka
Oct 18 '16 at 8:08




1




1





If the filesystem is sitting on a spinning platter hd (instead of ssd) then copying sequentially will be faster as the heads won't need to seek between the two different source and destination files. If on a RAID then things are more complicated as the files can be on (or even split over) several drives.

– Rycochet
Oct 18 '16 at 8:45





If the filesystem is sitting on a spinning platter hd (instead of ssd) then copying sequentially will be faster as the heads won't need to seek between the two different source and destination files. If on a RAID then things are more complicated as the files can be on (or even split over) several drives.

– Rycochet
Oct 18 '16 at 8:45










4 Answers
4






active

oldest

votes


















16














Assuming you want to cp files into a directory, you can use the usual syntax for cp:



cp mno.txt xyz.txt destination_directory


Or use brace expansion for brevity:



cp {mno,xyz}.txt destination_directory


For the sake of clarity, it is better to use the -t (--target-directory) option of cp, this is GNU-ism:



cp -t destination_directory {mno,xyz}.txt




Just to note, if you want to cp the contents of multiple files with one go of cp, you can't. cp deals with one file at a time when copying contents of one file to another.






share|improve this answer


























  • Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

    – Sergiy Kolodyazhnyy
    Oct 18 '16 at 7:25











  • @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

    – Piskvor
    Oct 18 '16 at 7:33








  • 1





    @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

    – Sergiy Kolodyazhnyy
    Oct 18 '16 at 7:37











  • @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

    – heemayl
    Oct 18 '16 at 7:39











  • For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

    – gerrit
    Oct 18 '16 at 11:37



















3














Use cp -t destination_dir/ file1 file2 syntax.



Example:



bash-4.3$ ls dir1
file1 file2 file3
bash-4.3$ ls dir2/
bash-4.3$ cp -t dir2/ dir1/file1 dir1/file2
bash-4.3$ ls dir2
file1 file2


Addition to original answer.



The uses who like to play with python , may be interested in the following script, which allows copying arbitrary number of files specified on command line, with last argument being the destination.



Demo:



bash-4.3$ ls dir1
file1 file2 file3
bash-4.3$ ls dir2
bash-4.3$ ./copyfiles.py dir1/file1 dir1/file2 dir2
bash-4.3$ ls dir2
file1 file2


Script itself:



#!/usr/bin/env python3
from shutil import copyfile
from os import path
from sys import argv

new_dir = path.realpath(argv[-1])
for f in argv[1:-1]:
base = path.basename(f)
orig_file = path.realpath(f)
new_file = path.join(new_dir,base)
copyfile(orig_file,new_file)





share|improve this answer





















  • 4





    What does the script do that cp doesn't?

    – Carsten S
    Oct 18 '16 at 7:26











  • @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

    – Sergiy Kolodyazhnyy
    Oct 18 '16 at 7:34











  • Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

    – Sergiy Kolodyazhnyy
    Oct 19 '16 at 20:47



















3














if you want to copy them at the same location (not to a new directory) to make backups, (for example), you can use a very small for loop to copy them with new names (here adding a .bak extension)



for f in {mno,xyz}.txt; do cp -- "$f" "$f".bak; done


{brace expansion} is the most succinct way to specify the particular files in your example, but you can use any suitable shell wildcards/globbing, or list out the files if necessary: for f in foo bar baz;






share|improve this answer

































    0














    You can do like this:



    cp {mno,xyz}.txt /path/to/destination


    Or if you need all .txt files:



    cp {*}.txt /path/to/destination




    share








    New contributor




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





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "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%2f838620%2fcopy-two-files-at-a-time%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      16














      Assuming you want to cp files into a directory, you can use the usual syntax for cp:



      cp mno.txt xyz.txt destination_directory


      Or use brace expansion for brevity:



      cp {mno,xyz}.txt destination_directory


      For the sake of clarity, it is better to use the -t (--target-directory) option of cp, this is GNU-ism:



      cp -t destination_directory {mno,xyz}.txt




      Just to note, if you want to cp the contents of multiple files with one go of cp, you can't. cp deals with one file at a time when copying contents of one file to another.






      share|improve this answer


























      • Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:25











      • @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

        – Piskvor
        Oct 18 '16 at 7:33








      • 1





        @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:37











      • @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

        – heemayl
        Oct 18 '16 at 7:39











      • For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

        – gerrit
        Oct 18 '16 at 11:37
















      16














      Assuming you want to cp files into a directory, you can use the usual syntax for cp:



      cp mno.txt xyz.txt destination_directory


      Or use brace expansion for brevity:



      cp {mno,xyz}.txt destination_directory


      For the sake of clarity, it is better to use the -t (--target-directory) option of cp, this is GNU-ism:



      cp -t destination_directory {mno,xyz}.txt




      Just to note, if you want to cp the contents of multiple files with one go of cp, you can't. cp deals with one file at a time when copying contents of one file to another.






      share|improve this answer


























      • Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:25











      • @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

        – Piskvor
        Oct 18 '16 at 7:33








      • 1





        @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:37











      • @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

        – heemayl
        Oct 18 '16 at 7:39











      • For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

        – gerrit
        Oct 18 '16 at 11:37














      16












      16








      16







      Assuming you want to cp files into a directory, you can use the usual syntax for cp:



      cp mno.txt xyz.txt destination_directory


      Or use brace expansion for brevity:



      cp {mno,xyz}.txt destination_directory


      For the sake of clarity, it is better to use the -t (--target-directory) option of cp, this is GNU-ism:



      cp -t destination_directory {mno,xyz}.txt




      Just to note, if you want to cp the contents of multiple files with one go of cp, you can't. cp deals with one file at a time when copying contents of one file to another.






      share|improve this answer















      Assuming you want to cp files into a directory, you can use the usual syntax for cp:



      cp mno.txt xyz.txt destination_directory


      Or use brace expansion for brevity:



      cp {mno,xyz}.txt destination_directory


      For the sake of clarity, it is better to use the -t (--target-directory) option of cp, this is GNU-ism:



      cp -t destination_directory {mno,xyz}.txt




      Just to note, if you want to cp the contents of multiple files with one go of cp, you can't. cp deals with one file at a time when copying contents of one file to another.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Oct 18 '16 at 7:04

























      answered Oct 18 '16 at 6:53









      heemaylheemayl

      68.4k11145216




      68.4k11145216













      • Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:25











      • @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

        – Piskvor
        Oct 18 '16 at 7:33








      • 1





        @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:37











      • @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

        – heemayl
        Oct 18 '16 at 7:39











      • For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

        – gerrit
        Oct 18 '16 at 11:37



















      • Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:25











      • @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

        – Piskvor
        Oct 18 '16 at 7:33








      • 1





        @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:37











      • @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

        – heemayl
        Oct 18 '16 at 7:39











      • For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

        – gerrit
        Oct 18 '16 at 11:37

















      Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

      – Sergiy Kolodyazhnyy
      Oct 18 '16 at 7:25





      Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not with cp. My script also does each file one by one. Simultaneous copying would require a very sophisticated algorithm, at least on the level of TCP algorithm

      – Sergiy Kolodyazhnyy
      Oct 18 '16 at 7:25













      @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

      – Piskvor
      Oct 18 '16 at 7:33







      @Serg: Very sophisticated? As in for fname in {mno,xyz}.txt ; do cp "${fname}" target_directory & done ? The & launches command in background, which essentially means "run them all at once". Note that since you're copying to the same destination (and over the same channel), the speed of simultaneous copy would probably be the same as serial copy, minus overhead. TL;DR: It's easy - but pointless.

      – Piskvor
      Oct 18 '16 at 7:33






      1




      1





      @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

      – Sergiy Kolodyazhnyy
      Oct 18 '16 at 7:37





      @Piskvor well, that's essentially creating multiple processes in background. Good approach, no doubt ! But what i am referring to is processing multiple files from the same one. That's also what heemayl alluded to - cp iterates over command line arguments, which is an obvious solution. OP hasn't clearly stated if that's what they want.

      – Sergiy Kolodyazhnyy
      Oct 18 '16 at 7:37













      @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

      – heemayl
      Oct 18 '16 at 7:39





      @Piskvor The thing you are doing clumsily in a loop cp is doing natively. I am not sure what you are trying to achieve here. Also, sending command in background is not necessarily simultaneous to multi-threading, also there is looping overhead involved.

      – heemayl
      Oct 18 '16 at 7:39













      For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

      – gerrit
      Oct 18 '16 at 11:37





      For the sake of clarify, one can also simply add a / to destination_directory, and there is no confusion.

      – gerrit
      Oct 18 '16 at 11:37













      3














      Use cp -t destination_dir/ file1 file2 syntax.



      Example:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2/
      bash-4.3$ cp -t dir2/ dir1/file1 dir1/file2
      bash-4.3$ ls dir2
      file1 file2


      Addition to original answer.



      The uses who like to play with python , may be interested in the following script, which allows copying arbitrary number of files specified on command line, with last argument being the destination.



      Demo:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2
      bash-4.3$ ./copyfiles.py dir1/file1 dir1/file2 dir2
      bash-4.3$ ls dir2
      file1 file2


      Script itself:



      #!/usr/bin/env python3
      from shutil import copyfile
      from os import path
      from sys import argv

      new_dir = path.realpath(argv[-1])
      for f in argv[1:-1]:
      base = path.basename(f)
      orig_file = path.realpath(f)
      new_file = path.join(new_dir,base)
      copyfile(orig_file,new_file)





      share|improve this answer





















      • 4





        What does the script do that cp doesn't?

        – Carsten S
        Oct 18 '16 at 7:26











      • @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:34











      • Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

        – Sergiy Kolodyazhnyy
        Oct 19 '16 at 20:47
















      3














      Use cp -t destination_dir/ file1 file2 syntax.



      Example:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2/
      bash-4.3$ cp -t dir2/ dir1/file1 dir1/file2
      bash-4.3$ ls dir2
      file1 file2


      Addition to original answer.



      The uses who like to play with python , may be interested in the following script, which allows copying arbitrary number of files specified on command line, with last argument being the destination.



      Demo:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2
      bash-4.3$ ./copyfiles.py dir1/file1 dir1/file2 dir2
      bash-4.3$ ls dir2
      file1 file2


      Script itself:



      #!/usr/bin/env python3
      from shutil import copyfile
      from os import path
      from sys import argv

      new_dir = path.realpath(argv[-1])
      for f in argv[1:-1]:
      base = path.basename(f)
      orig_file = path.realpath(f)
      new_file = path.join(new_dir,base)
      copyfile(orig_file,new_file)





      share|improve this answer





















      • 4





        What does the script do that cp doesn't?

        – Carsten S
        Oct 18 '16 at 7:26











      • @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:34











      • Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

        – Sergiy Kolodyazhnyy
        Oct 19 '16 at 20:47














      3












      3








      3







      Use cp -t destination_dir/ file1 file2 syntax.



      Example:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2/
      bash-4.3$ cp -t dir2/ dir1/file1 dir1/file2
      bash-4.3$ ls dir2
      file1 file2


      Addition to original answer.



      The uses who like to play with python , may be interested in the following script, which allows copying arbitrary number of files specified on command line, with last argument being the destination.



      Demo:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2
      bash-4.3$ ./copyfiles.py dir1/file1 dir1/file2 dir2
      bash-4.3$ ls dir2
      file1 file2


      Script itself:



      #!/usr/bin/env python3
      from shutil import copyfile
      from os import path
      from sys import argv

      new_dir = path.realpath(argv[-1])
      for f in argv[1:-1]:
      base = path.basename(f)
      orig_file = path.realpath(f)
      new_file = path.join(new_dir,base)
      copyfile(orig_file,new_file)





      share|improve this answer















      Use cp -t destination_dir/ file1 file2 syntax.



      Example:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2/
      bash-4.3$ cp -t dir2/ dir1/file1 dir1/file2
      bash-4.3$ ls dir2
      file1 file2


      Addition to original answer.



      The uses who like to play with python , may be interested in the following script, which allows copying arbitrary number of files specified on command line, with last argument being the destination.



      Demo:



      bash-4.3$ ls dir1
      file1 file2 file3
      bash-4.3$ ls dir2
      bash-4.3$ ./copyfiles.py dir1/file1 dir1/file2 dir2
      bash-4.3$ ls dir2
      file1 file2


      Script itself:



      #!/usr/bin/env python3
      from shutil import copyfile
      from os import path
      from sys import argv

      new_dir = path.realpath(argv[-1])
      for f in argv[1:-1]:
      base = path.basename(f)
      orig_file = path.realpath(f)
      new_file = path.join(new_dir,base)
      copyfile(orig_file,new_file)






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Oct 18 '16 at 7:17

























      answered Oct 18 '16 at 6:49









      Sergiy KolodyazhnyySergiy Kolodyazhnyy

      75.6k9156331




      75.6k9156331








      • 4





        What does the script do that cp doesn't?

        – Carsten S
        Oct 18 '16 at 7:26











      • @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:34











      • Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

        – Sergiy Kolodyazhnyy
        Oct 19 '16 at 20:47














      • 4





        What does the script do that cp doesn't?

        – Carsten S
        Oct 18 '16 at 7:26











      • @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

        – Sergiy Kolodyazhnyy
        Oct 18 '16 at 7:34











      • Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

        – Sergiy Kolodyazhnyy
        Oct 19 '16 at 20:47








      4




      4





      What does the script do that cp doesn't?

      – Carsten S
      Oct 18 '16 at 7:26





      What does the script do that cp doesn't?

      – Carsten S
      Oct 18 '16 at 7:26













      @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

      – Sergiy Kolodyazhnyy
      Oct 18 '16 at 7:34





      @CarstenS it does exactly the same thing :) that's the whole point - provide alternative approach, different perspective on the same task.

      – Sergiy Kolodyazhnyy
      Oct 18 '16 at 7:34













      Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

      – Sergiy Kolodyazhnyy
      Oct 19 '16 at 20:47





      Somebody downvoted my answer.By definition, downvote means that answer isn't useful. I'd like to point out, that my answer provides a proper solution of using cp -t DEST FILE1 FILE2 . . . and extra material as well. Just because you don't like alternative solutions or extra material added to answers, doesn't make my answer not useful :)

      – Sergiy Kolodyazhnyy
      Oct 19 '16 at 20:47











      3














      if you want to copy them at the same location (not to a new directory) to make backups, (for example), you can use a very small for loop to copy them with new names (here adding a .bak extension)



      for f in {mno,xyz}.txt; do cp -- "$f" "$f".bak; done


      {brace expansion} is the most succinct way to specify the particular files in your example, but you can use any suitable shell wildcards/globbing, or list out the files if necessary: for f in foo bar baz;






      share|improve this answer






























        3














        if you want to copy them at the same location (not to a new directory) to make backups, (for example), you can use a very small for loop to copy them with new names (here adding a .bak extension)



        for f in {mno,xyz}.txt; do cp -- "$f" "$f".bak; done


        {brace expansion} is the most succinct way to specify the particular files in your example, but you can use any suitable shell wildcards/globbing, or list out the files if necessary: for f in foo bar baz;






        share|improve this answer




























          3












          3








          3







          if you want to copy them at the same location (not to a new directory) to make backups, (for example), you can use a very small for loop to copy them with new names (here adding a .bak extension)



          for f in {mno,xyz}.txt; do cp -- "$f" "$f".bak; done


          {brace expansion} is the most succinct way to specify the particular files in your example, but you can use any suitable shell wildcards/globbing, or list out the files if necessary: for f in foo bar baz;






          share|improve this answer















          if you want to copy them at the same location (not to a new directory) to make backups, (for example), you can use a very small for loop to copy them with new names (here adding a .bak extension)



          for f in {mno,xyz}.txt; do cp -- "$f" "$f".bak; done


          {brace expansion} is the most succinct way to specify the particular files in your example, but you can use any suitable shell wildcards/globbing, or list out the files if necessary: for f in foo bar baz;







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 18 '16 at 7:27

























          answered Oct 18 '16 at 7:03









          ZannaZanna

          51.4k13141243




          51.4k13141243























              0














              You can do like this:



              cp {mno,xyz}.txt /path/to/destination


              Or if you need all .txt files:



              cp {*}.txt /path/to/destination




              share








              New contributor




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

























                0














                You can do like this:



                cp {mno,xyz}.txt /path/to/destination


                Or if you need all .txt files:



                cp {*}.txt /path/to/destination




                share








                New contributor




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























                  0












                  0








                  0







                  You can do like this:



                  cp {mno,xyz}.txt /path/to/destination


                  Or if you need all .txt files:



                  cp {*}.txt /path/to/destination




                  share








                  New contributor




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










                  You can do like this:



                  cp {mno,xyz}.txt /path/to/destination


                  Or if you need all .txt files:



                  cp {*}.txt /path/to/destination





                  share








                  New contributor




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








                  share


                  share






                  New contributor




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









                  answered 8 mins ago









                  Mher AsatryanMher Asatryan

                  1




                  1




                  New contributor




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





                  New contributor





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






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






























                      draft saved

                      draft discarded




















































                      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%2f838620%2fcopy-two-files-at-a-time%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

                      GameSpot

                      日野市

                      Tu-95轟炸機