24

Is it possible to run cp again after it was aborted and make it start where it ended last time (not overwrite data that's already copied, only copy what's still left)?

splattne
  • 28,348
  • 19
  • 97
  • 147
Phil
  • 1,839
  • 6
  • 27
  • 33

4 Answers4

37

It's cases like this that have taught me to use rsync from the start. However in your case, you can use rsync now. It will only copy new data across, including if cp stopped half way through a big file.

You can use it just like cp, like this:

rsync --append /where/your/copying/from /where/you/want/to/copy
Amandasaurus
  • 30,211
  • 62
  • 184
  • 246
11

In case the aborted cp was a recursive copy, you might want to resume with rsync including the option --recursive.

Example

Aborted copy command:

cp -r source-directory destination-directory

Let us assume that destination-directory already existed, so that this copy command created a directory named source-directory within destination-directory. This can be resumed via:

rsync --recursive --append source-directory destination-directory

Note that trailing slashes have a precise meaning in rsync path options.

In this case, the copy command could have gotten the argument source-directory or source-directory/, it does not make a difference. In the rsync command, however, it must be source-directory without trailing slash.

8

Use the -u switch, and see the cp man page.

Sven
  • 97,248
  • 13
  • 177
  • 225
  • but source files didn't changed or anything – Phil Aug 22 '09 at 00:29
  • 4
    the -u is for 'update' only... ie: it wont overwrite the existing files in the destination _if_ they are same or newer... – ericslaw Aug 22 '09 at 04:27
  • 4
    If you use -u, then it will copy the same big file again. -u only helps if you're trying to resume a large recursive copy. – Amandasaurus Jan 14 '10 at 17:05
  • 1
    This answer was helpful for me because in my case it was many small-ish files and no problem to just delete the incomplete files before running my initial `cp -a` as `cp -au` again. – msa May 13 '21 at 11:58
  • Should I be worried about unfinished files from the previous `cp`? Or the `-u` will take care of that? – Qin Heyang Nov 01 '21 at 18:35
5

rsync is a great tool also: man page at -> http://www.manpagez.com/man/1/rsync/

ForgeMan
  • 391
  • 1
  • 8