bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to overwrite the destination directory by 'cp'?


From: Bob Proulx
Subject: Re: How to overwrite the destination directory by 'cp'?
Date: Mon, 25 Jan 2010 11:08:22 -0700
User-agent: Mutt/1.5.18 (2008-05-17)

Peng Yu wrote:
> Suppose I have directory a and b, the following command will copy the
> content of a to b/a, rather than overwrite the directory 'b' by the
> directory 'a'. I'm wondering if there is an option to overwrite 'b'?
> 
> cp -r a b

The 'cp' command will always copy source to destination.  This means
that if you run the command multiple times that it will wastefully
copy the data (possibly very large files) each and every time.

The 'rsync' command is much better suited to that type of operation.
Instead of using 'cp' please consider using 'rsync' instead.  It will
much more efficiently detect whether files need to be copied or
whether files need to be deleted and do the right thing.  It can be
run repeatedly (is idempotent) and very efficient.

  rsync -n -a -v a/ b/

Use with --delete may be appropriate.

  rsync -n --delete -a -v a/ b/

The -n is "not really" and will only perform a trial run.  I recommend
always testing with -n when also using --delete since a mistake can
delete something unintentionally.  Remove the -n option when you have
tested it and are satisfied as to the behavior.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]