What's the difference between ` cp ` and ` rsync `? [closed]
Being brief (a small book could be written on the topic), maybe it is useful to think like this:
-
cp
is for duplicating stuff and by default only ensures files have unique full path names -
rsync
is for synchronising stuff and uses the size and timestamp of files to decide if they should be replaced. It has many more options and capabilities thancp
Using their various options, you can use either of them for many tasks, for example cp -u
can replace only files that are newer, as rsync
is used to do.
But there are some tasks where one has advantages over the other
You might as well use cp
when you want to make a local duplicate file or directory. For example, you want to edit an important file, so you make a backup first:
cp .bashrc bashrc-bak
Making rsync
do this would require three more keystrokes, so why bother? If you want to duplicate a directory
cp -r ~/Desktop/cakes ~/Recipes/cakes
serves you well. Why bother typing rsync -a
? Well you might, since its -v
verbose option gives more interesting and useful output.
However, let's say you're updating a backup of some directory on your system on a flash drive. The directory already exists on the flash drive, and you just want to sync the files so it has the latest version of your stuff. rsync
is much faster than cp
for this, because it will check file sizes and timestamps to see which ones need to be updated, and you can add more refinements. You can even make it do a checksum instead of the default 'quick check', although this will take longer.
You can also use rsync
to copy or sync files to a remote machine, or make is run as a daemon. Humble cp
can't do such fancy things.
To learn the options and syntax ("structure"?) (which is very similar) read man
and info
pages and practise!