rsync is the tool when it comes to shuffling around data reliably. Be it on the local machine or between remote servers. The usual use case is: Make sure this folder has the same contents of that folder. This would do:
rsync to be verbose and
-a (“archive”) enables a couple of options you’d want by default (copy files recursively, keep timestamps & permissions, etc.).
rsync is able to sync the contents two folders or to sync one folder into another.
One has to be very careful with that.
Depending on whether a trailing slash is provided for the source directory,
rsync will either sync the contents of src & dst or sync src into dst.
Let’s see what this means exactly.
See? Usually, the first execution is what you want: One expects
rsync to sync the two given folders.
You need to provide a trailing slash after
src in order to achieve this.
Or: No trailing whitespace at after
src but the provided target directory is one level up, i.e.
/path/to instead of
The advantage of using the trailing slash is that the two folders (source & destination) do not have to share the same name as shown in the example above.
Note that it doesn’t make a difference if
dst doesn’t exist (
rsync creates it if needed) or whether you provide a trailing whitespace after
dst or not.
By the way: When running
rsync interactively, the
--progress command line switch is quite handy.
It shows - for each file - the transmitted file size and the estimated remaining transmission time.