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.

I am using the following command to copy contents from a source directory to a destination directory:

cp src/* dest

However, after evoking this command and while when contents are getting copied, if I create some more files in the src directory , these newly created files are not copied to the dest directory.

Could you please explain the reason behind it? Does cp work on something like making account of contents while cp is fired and then copying the contents based in that account keeping and thus ignoring the newly created contents?

share|improve this question
3  
All the important parts of this happen in userspace, not kernelspace –  awoodland Jan 21 '12 at 9:10
add comment

migrated from stackoverflow.com Jan 23 '12 at 18:50

This question came from our site for professional and enthusiast programmers.

2 Answers

That is because "src/*" is not evaluated (expanded into a list of files) by cp, but by the shell prior to invoking cp.

share|improve this answer
add comment

Andreas is right that src/* is expanded by the shell. However, even if you don't specify the wildcard cp might still skip your newly created files because there will be a race condition between the cp process accessing the directory and you (actually, the process that creates files on your behalf) modifying the directory.

As far as the implementation of GNU cp is concerned, it does get a list of the directory entries before actual copying (see the copy_dir function here).

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.