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.
4 Answers
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.
- You mean not available as part of the default installation but a separate download?Jim– Jim2013-09-15 16:24:30 +00:00Commented Sep 15, 2013 at 16:24
- 1@Jim yes, sometimes you need to install
rsyncyourself depending on the system you find yourself on. If you don't haverootaccess that can be hard.cpis POSIX and will always be there.2013-09-15 16:25:31 +00:00Commented Sep 15, 2013 at 16:25 - 10
cpis part of the GNU coreutils so it is always installed on every Linux system whilersyncis not.Martin von Wittich– Martin von Wittich2013-09-15 16:58:20 +00:00Commented Sep 15, 2013 at 16:58 - 2
sometimes it is just not worth typing those few extra characters- I've aliasedpcp(for "progress copy") for that ;)Izkata– Izkata2013-09-15 23:43:56 +00:00Commented Sep 15, 2013 at 23:43
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.
- 1Underneath, rsync's copy methodology is significantly slower. See unix.stackexchange.com/questions/374071/… . An strace of cp shows (as of this writing), a simple 32KB read/32 KB write sequence of operations. Rsync, meanwhile, does a read/4092-byte + 4-byte write to socket/read from socket/250KB write to file. I am doing an rsync of 36T of mixed size files at 130MB/s throughput. I can triple that with cp -a. rsync wins, as you say when you want to "make 'that' look like 'this'" on directories that are already similar.Mike S– Mike S2017-06-29 14:55:45 +00:00Commented Jun 29, 2017 at 14:55
I think rsync doesn't handle copying sparse file in a straightforward manner. cp by default handles that very well.
- 6It does with the
-Sflag.2013-09-15 16:59:56 +00:00Commented Sep 15, 2013 at 16:59 - 2@terdon, Oh well, please refer to this article: barricane.com/rsync-vm-sparse-inplace-kvm-vmware.wcang– wcang2013-09-15 17:35:26 +00:00Commented Sep 15, 2013 at 17:35
- Ah, thanks, you should add that to your answer. I just quickly searched the man page for
sparse.2013-09-15 17:38:43 +00:00Commented Sep 15, 2013 at 17:38
Because this cp flag is lacking in rsync:
-i, --interactive prompt before overwrite (overrides a previous -n option) - No, although there is
-n(dry run) on rsync, which can be kind of a substitute to that feature.Niloct– Niloct2015-02-16 03:19:28 +00:00Commented Feb 16, 2015 at 3:19
rsyncins't available everywhere,cpis.cpbut notrsync: pubs.opengroup.org/onlinepubs/007904875/utilities/contents.htm