several cp -r xxx . & are overwriting themselves

1

I have launched several:

cp -r folder1 /home/USBkey/. &
cp -r folder2 /home/USBkey/. &
cp -r folder3 /home/USBkey/. &

Each folder contains mp3 files. At the end of all copies, when I listen to one mp3 in folder1 I can hear for a short time (2 or 3secs) a part of a song from folder3 for instance. Like "cp" doesn't care to other parallel "cp" and write inside another memory space it should.

Some advise about this?

Thanks

FTG

Posted 2017-06-27T12:49:23.130

Reputation: 13

1AFAIK running them in parallel is not faster than running them in sequence, especially to copy from/to a USB key. If you don't get an actual answer to your question and still have problems, try 1. copying your files from your graphical file explorer (if you have one) or 2. running the 3 cps in sequence with &&. – Nathan.Eilisha Shiraini – 2017-06-27T12:55:08.723

As @NathanShiraini says, you need to copy in sequence, though it is probably better not to use &&, which will stop subsequent copies if there is an error in an earlier copy. – AFH – 2017-06-27T13:11:31.973

@NathanShiraini: it is not only an issue of how it is fast but also that cp in parallel seems to mix the audio files... very weird. How to perform subsequent copy without && and in one line? – FTG – 2017-06-27T13:36:13.270

@FTG I know, but I do not know what are the gurratees of cpregarding parallel execution, so I didn't mention it. As for sequential execution of multiple commands, you can use ; as the separator to run each command regardless of the result of the last one. E.G.: cp -r folder1 /home/USBkey/. ; cp -r folder2 /home/USBkey/. ; cp -r folder3 /home/USBkey/. – Nathan.Eilisha Shiraini – 2017-06-27T13:43:24.950

Answers

1

You can copy the folders content as:

cp -r folder1/ folder2/ folder3/ /home/USBkey/.

If you want to have the folders inside the /home/USBkey/ directory only remvoe the / as:

cp -r folder1 folder2 folder3 /home/USBkey/.

This still being a copy in sequence.

Genaro Morales

Posted 2017-06-27T12:49:23.130

Reputation: 315

+1 for the single command form, unlike in my comments! By the way, when typing code, remember to surround it in `` backticks or indent it with four spaces. – Nathan.Eilisha Shiraini – 2017-06-27T17:42:03.067