-2

I need to copy files from several folders by separate cp commands. How to ensure that every command ended only after what files are actually copied to disk? How can I find out that the copying was finished?

Thanks

rojomoke
  • 3,765
  • 2
  • 21
  • 30
peterko
  • 503
  • 1
  • 6
  • 18
  • 1
    You are asking about interprocess-communication; you'll need to provide full details about what is calling `cp` and what needs to wait on the `cp` caller. – chepner Aug 14 '15 at 11:47
  • I always thought you were just supposed to wait until the light stopped blinking on the floppy drive? – David C. Rankin Aug 14 '15 at 14:10

1 Answers1

1

If I understand correctly - separate your commands with &&. Like this:

cp -r ./stuff/* ./somewhereelse/ && cp -r ./otherstuff/* ./somewhereelse/ && cp -r ./otherstuff/* ./anotherplace/

The && will ensure the next command is run on success of the previous. You can chain as many commands as you like this way.

Alex
  • 335
  • 2
  • 11
  • Ok, but how can I wait for last cp command? Then I use files for other processing and sometimes is copying to slow and files missing. – peterko Aug 14 '15 at 11:35
  • From where do you need to know that the command has completed? – Alex Aug 14 '15 at 11:38
  • For example I need to know that this part `cp -r ./otherstuff/* ./somewhereelse/` is finished and I can processed files in another program. Another program is in Node.js – peterko Aug 14 '15 at 11:42
  • Add another && and stick it on, if were still talking Bash - I've edited the answer to reflect that. – Alex Aug 14 '15 at 11:44
  • NO, files are processed in Node.js. No in bash. That is a problem. – peterko Aug 14 '15 at 11:45
  • Then, this'll be a node.js question, won't it? Never used Node myself. – Alex Aug 14 '15 at 11:48