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?

  • 3
    All the important parts of this happen in userspace, not kernelspace
    – awoodland
    Jan 21, 2012 at 9:10

2 Answers 2


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


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).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .