21

They seem similar to me. I want to know how to use them. What's the difference in structure?

2
  • What do you mean by "structure"?
    – edwinksl
    Aug 3, 2016 at 5:05
  • Check grsync, a graphical version of rsync ( install with sudo apt-get install grsync). There you will see how powerful rsync is. Minding this, cp is powerful too, but its focus is not in synchronization, and so, less configurable in that sense.
    – user308164
    Aug 3, 2016 at 7:43

2 Answers 2

17

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 than cp

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!

0

cp is simple tool that was here since ever and it is used for simply copy from one place to another on your local filesystem. It does just blind copy and might ask for overwriting the files.

On the other side, rsync is complex tool to syncing two directories/files, not necessarily on the same filesystem (you can rsync over ssh, ftp, ...) and it has a lot of features to save your bandwidth or time (does not have to copy everything, if the files are the same).

Not the answer you're looking for? Browse other questions tagged .