Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cp large amount of files w/o overwritting

Status
Not open for further replies.

bluedragon2

IS-IT--Management
Jan 24, 2003
2,642
US
Is it possible to copy a large number of files without overwriting existing files and not use the interactive option?

Thanks

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
You can use rsync to do that, it doesn't have to be across networks.

Alternatively you can use cpio like this:

Code:
cd /srcdir
find . | cpio -vdmp /targetdir

Annihilannic.
 
Thanks, we can not use rsync for this one. I was looking at the cpio, but not get to in-depth with it yet.

Thanks...

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Actually... I forgot to check, the existing files, will they have the same dates as those in the source location? Because cpio will overwrite them if the source files are newer; it only skips them if the destination files are newer. So it may not be exactly what you require.

Annihilannic.
 
It may be worth looking at:
set -o noclobber (in ksh

to prevent existing files being overwritten. I've not really used it apart from a quick test. If the file exists, the copy command (or whatever is trying overwrite the file) errors with something like:
/bin/ksh: <the-filename>: file already exists


I hope that helps.

Mike
 
Thanks all, I ended up writing a quick script to copy the files. Ran out of time as usual :)

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
noclobber only affects file creation by the shell, for example by redirection. Other utilities such as cp are unaffected.

Code:
$ touch a b
$ cp a b
$ echo > a
$ set -o noclobber
$ echo > a
ksh: a: file already exists
$ cp a b
$

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top