diff script to copy files to other dir when not exists

I have two directories that are mostly the same:

dir1
dir2

Is there an easy way to take the output of diff and copy files from dir1 that do not exist in dir2 - but copy them to the same path (many nested directories).

am only trying to copy files in dir1 that do not exist in dir2.

thanks

But what do you mean by:

?

GNU cp has the -u option:

   -u, --update
              copy only when the SOURCE file is newer than the destination file or when the destination file is miss-
              ing

It doesn't match exactly your requirement, of course.

I do not want to copy the entire directory.

I just want to copy only those files that exist in dir1 to dir2 with the same path.
any ideas or help there?

---------- Post updated at 01:58 PM ---------- Previous update was at 01:57 PM ----------

so if:

dir1/path1/path2/path3/file_exists.txt is here in dir1 but not dir2, then I want to copy file_exists.txt over to dir2 with the same path: like: dir2/path1/path2/path3/file_exists.txt

---------- Post updated at 01:59 PM ---------- Previous update was at 01:58 PM ----------

so if:

dir1/path1/path2/path3/file_exists.txt is here in dir1 but not dir2, then I want to copy file_exists.txt over to dir2 with the same path: like: dir2/path1/path2/path3/file_exists.txt

If you have rsync installed, you can go that route. It'll only copy new files in dir1 to dir2. Just cd into dir1 and run "rsync -avz --stats * /tmp/dir2" and it should only copy files that do not already exist in dir2.

Hope this helps.

OK, I will try that. Also another requirement is that I want to skip certain meta-data directories like "CVS/". Is there a way to exclude a list of directories?

Also I do not want to copy files that differ, just files that do not exist in one, that do exist in the other. What flag controls this behaviour?