×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

cp large amount of files w/o overwritting

cp large amount of files w/o overwritting

cp large amount of files w/o overwritting

(OP)
Is it possible to copy a large number of files without overwriting existing files and not use the interactive option?

Thanks

Blue Dragon

If I wasn't Blue, I would just be a Dragon...

RE: cp large amount of files w/o overwritting

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.

RE: cp large amount of files w/o overwritting

(OP)
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 Dragon

If I wasn't Blue, I would just be a Dragon...

RE: cp large amount of files w/o overwritting

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.

RE: cp large amount of files w/o overwritting

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

RE: cp large amount of files w/o overwritting

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

Blue Dragon

If I wasn't Blue, I would just be a Dragon...

RE: cp large amount of files w/o overwritting

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close