Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I wanted to ask is there any reason not to use rsync for everything and abandon cp?
I wasn't aware of rsync and now I don't know why cp is ever needed.

share|improve this question
7  
rsync ins't available everywhere, cp is. –  Mat Sep 15 '13 at 16:22
3  
Which installation? Linux? Which one? Unix? ditto. BSD? You never know what comes by default. –  terdon Sep 15 '13 at 16:24
5  
There really ins't a "default installation" for Linux. Every distro has its set of core packages and a host of variations in those. Also when you need to work on a lot of systems, using the tools available everywhere makes things simpler. –  Mat Sep 15 '13 at 16:25
4  
@Mat : There is a default (or core) installation in so far as linux distros comply, via the base GNU userland, with POSIX, which requires (and defines the functioning of) cp but not rsync: pubs.opengroup.org/onlinepubs/007904875/utilities/contents.htm –  TAFKA 'goldilocks' Sep 15 '13 at 17:34
1  
I'm pretty sure Debian GNU/Linux installs rsync by default. It is, however, not available in the installation and rescue environment. (I used that early today to transfer the contents of my root partition from one disk to another. Used the 7.1.0 amd64 install DVD.) –  Michael Kjörling Sep 15 '13 at 19:42
show 4 more comments

4 Answers

up vote 21 down vote accepted

Strictly speaking yes, you can always use rsync. From man rsync (emphasis mine):

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be
copied. It is famous for its delta-transfer algo‐ rithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destina‐ tion. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

Now, sometimes it is just not worth typing those few extra characters just to use a tank to kill a fly. Also, rsync is often not installed by default so cp is nice to have.

share|improve this answer
    
You mean not available as part of the default installation but a separate download? –  Jim Sep 15 '13 at 16:24
1  
@Jim yes, sometimes you need to install rsync yourself depending on the system you find yourself on. If you don't have root access that can be hard. cp is POSIX and will always be there. –  terdon Sep 15 '13 at 16:25
8  
cp is part of the GNU coreutils so it is always installed on every Linux system while rsync is not. –  Martin von Wittich Sep 15 '13 at 16:58
1  
sometimes it is just not worth typing those few extra characters - I've aliased pcp (for "progress copy") for that ;) –  Izkata Sep 15 '13 at 23:43
add comment

Rsync can be slower than cp in some situations. For example when the destination exists and rsync ends up doing some expensive comparisons for each block, does not find equal blocks and copies the complete source file anyways.

Also when destination files don't exist, rsync does not provide any advantage above cp.

share|improve this answer
add comment

I think rsync doesn't handle copying sparse file in a straightforward manner. cp by default handles that very well.

share|improve this answer
4  
It does with the -S flag. –  terdon Sep 15 '13 at 16:59
    
Cool. I'll use that next time. Thanks. –  wcang Sep 15 '13 at 17:04
2  
@terdon, Oh well, please refer to this article: barricane.com/rsync-vm-sparse-inplace-kvm-vmware. –  wcang Sep 15 '13 at 17:35
    
Ah, thanks, you should add that to your answer. I just quickly searched the man page for sparse. –  terdon Sep 15 '13 at 17:38
add comment

Because this cp flag is lacking in rsync:

-i, --interactive
       prompt before overwrite (overrides a previous -n option)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.