I don't quite understand your use of xargs
, and particularly the meaning of %
.
But about cp
, yes it will overwrite the destination files. However, cp
has several options to take care of this:
-b
or --backup[=CONTROL]
: make a backup of each existing destination file
-i
or --interactive
: prompt before overwrite (overrides a previous -n option)
-n
or --no-clobber
: do not overwrite an existing file
-u
or --update
: copy only when the SOURCE file is newer than the destination file or when the destination file is missing
See man cp
for more.
As for your ultimate goal, I think that what you mean is to copy some files under "test/" listed in your input.txt
file, to the same path under "prod/". For that, it seems rsync
might be better suited. It has tons of options. A few of those which may be relevant :
-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
--files-from=FILE read list of source-file names from FILE
-R, --relative` use relative path names
-u, --update skip files that are newer on the receiver
-n, --dry-run perform a trial run with no changes made
[etc]