Recursive, Non-Overwriting File Copy?

You could use rsync (it also does local copy)

rsync -r --ignore-existing --include=*/ --include=*.js --exclude=* source/ destination
  • -r to recurse into directories,
  • --ignore-existing to ignore existing files in destination,
  • the include and exclude filters mean: include all directories, include all *.js files, exclude the rest; the first include is needed, otherwise the final exclude will also exclude directories before their content is scanned.

Finally, you can add a -P if you want to watch progress, a --list-only if you want to see what it would copy without actually copying, and a -t if you want to preserve the timestamps.


This is not related, but I learned the rsync command recently, when I moved 15 years of documents from one partition to another. Confident that my files were there, I then wiped the old partition and put some other stuff in there; I realized later that I lost all the timestamps, and discovered the -t flag. Just wanted to share my distress :'(


This is also achievable using cp. See here:

sudo cp -vnpr /xxx/* /yyy

xxx = source

yyy = destination

v = verbose

n = no clobber (no overwrite)

p = preserve permissions

r = recursive


Looking at the man pages it seems that you want the -n option.

-n, --no-clobber
   do not overwrite an existing file (overrides the previous -i option)