copy two files at a time Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Copy files from a directory to a sub-directory (excluding the sub-directory itself)Copy several filesCopy all folders with name “ABC” to another locationHow can I recursively copy files by file extension?copy files by dateHow to copy everything from one directory to another using 'cp' command?How to copy an entire directory except one file in each sub-directory via terminal?Copy particular files (whose names are saved in a list) from one folder to anotherHow to copy only files (.wrk) from multiple directories and subfoldersSED copy specific section to different files
What would you call this weird metallic apparatus that allows you to lift people?
Is CEO the "profession" with the most psychopaths?
Is there a kind of relay that only consumes power when switching?
Chinese Seal on silk painting - what does it mean?
What was the first language to use conditional keywords?
Hangman Game with C++
How does Python know the values already stored in its memory?
Selecting user stories during sprint planning
Is it a good idea to use CNN to classify 1D signal?
If Windows 7 doesn't support WSL, then what does Linux subsystem option mean?
How to compare two different files line by line in unix?
How to write this math term? with cases it isn't working
Can the Great Weapon Master feat's damage bonus and accuracy penalty apply to attacks from the Spiritual Weapon spell?
Illegal assignment from sObject to Id
Why weren't discrete x86 CPUs ever used in game hardware?
Dating a Former Employee
Generate an RGB colour grid
What are the diatonic extended chords of C major?
Why is it faster to reheat something than it is to cook it?
How to write the following sign?
Did Deadpool rescue all of the X-Force?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
Is there hard evidence that the grant peer review system performs significantly better than random?
Why is the AVR GCC compiler using a full `CALL` even though I have set the `-mshort-calls` flag?
copy two files at a time
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Copy files from a directory to a sub-directory (excluding the sub-directory itself)Copy several filesCopy all folders with name “ABC” to another locationHow can I recursively copy files by file extension?copy files by dateHow to copy everything from one directory to another using 'cp' command?How to copy an entire directory except one file in each sub-directory via terminal?Copy particular files (whose names are saved in a list) from one folder to anotherHow to copy only files (.wrk) from multiple directories and subfoldersSED copy specific section to different files
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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
add a comment |
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
Copy to where? ToABC
?
– 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
add a comment |
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
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
command-line files cp
asked Oct 18 '16 at 6:47
Avani badhekaAvani badheka
1,0414929
1,0414929
Copy to where? ToABC
?
– 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
add a comment |
Copy to where? ToABC
?
– 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
add a comment |
4 Answers
4
active
oldest
votes
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.
Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not withcp
. 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 infor 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 loopcp
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/
todestination_directory
, and there is no confusion.
– gerrit
Oct 18 '16 at 11:37
|
show 1 more comment
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)
4
What does the script do thatcp
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 usingcp -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
add a comment |
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;
add a comment |
You can do like this:
cp mno,xyz.txt /path/to/destination
Or if you need all .txt files:
cp *.txt /path/to/destination
New contributor
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not withcp
. 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 infor 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 loopcp
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/
todestination_directory
, and there is no confusion.
– gerrit
Oct 18 '16 at 11:37
|
show 1 more comment
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.
Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not withcp
. 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 infor 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 loopcp
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/
todestination_directory
, and there is no confusion.
– gerrit
Oct 18 '16 at 11:37
|
show 1 more comment
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.
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.
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 withcp
. 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 infor 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 loopcp
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/
todestination_directory
, and there is no confusion.
– gerrit
Oct 18 '16 at 11:37
|
show 1 more comment
Disregard the previous comment. I understand now you're referring to basically simultaneous copying of files. That indeed cannot be done, at least not withcp
. 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 infor 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 loopcp
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/
todestination_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
|
show 1 more comment
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)
4
What does the script do thatcp
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 usingcp -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
add a comment |
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)
4
What does the script do thatcp
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 usingcp -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
add a comment |
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)
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)
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 thatcp
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 usingcp -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
add a comment |
4
What does the script do thatcp
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 usingcp -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
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
edited Oct 18 '16 at 7:27
answered Oct 18 '16 at 7:03
ZannaZanna
51.4k13141243
51.4k13141243
add a comment |
add a comment |
You can do like this:
cp mno,xyz.txt /path/to/destination
Or if you need all .txt files:
cp *.txt /path/to/destination
New contributor
add a comment |
You can do like this:
cp mno,xyz.txt /path/to/destination
Or if you need all .txt files:
cp *.txt /path/to/destination
New contributor
add a comment |
You can do like this:
cp mno,xyz.txt /path/to/destination
Or if you need all .txt files:
cp *.txt /path/to/destination
New contributor
You can do like this:
cp mno,xyz.txt /path/to/destination
Or if you need all .txt files:
cp *.txt /path/to/destination
New contributor
New contributor
answered 15 mins ago
Mher AsatryanMher Asatryan
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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