Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I use cp to copy a directory to another place. If the process takes long, and I create a new file under the source directory, will it be copied, or does it depend on something?

share|improve this question
up vote 1 down vote accepted

If you create a new file while cp is operating, it's likely that it won't be picked up. That might depend on the cp implementation: some gather a list of files when they start, others do it by chunks. If it's a recursive copy, all the cp implementations I've seen work directory by directory, so if you add the file to a directory that cp hasn't traversed yet, it will be copied.

If you add a file midway and you want to copy it, run rsync afterwards (after the copy is finished and the new file is fully written). Rsync will only copy the added file.

You can run rsync from the start (use rsync -a to do a recursive copy and preserve metadata). Rsync can do pretty much everything cp can do and much more, so you can ignore cp and always use rsync if you like (except on embedded systems that don't have rsync).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.