0

I would like to append new files to an existing directory in terminal. So I'm using :

cp -r pathtodirectory/directory/ directory

but I do not want to overwrite, I just want to update. Any ideas?

fedorqui
  • 275,237
  • 103
  • 548
  • 598

1 Answers1

0
find pathtodirectory/directory -maxdepth 1 -type f -exec sh -c \
    'for f; do ff="directory/$(basename $f)"; if [[ ! -f "$ff" ]]; then echo "Copying $f" && cp "$f" "$ff"; fi; done' sh {} +

LIMITATIONS:

  • no spaces/glob characters in filenames
Eugeniu Rosca
  • 5,177
  • 16
  • 45