Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.