links, devices, attributes, permissions, ownerships, etc. are preserved
in the transfer. Additionally, compression will be used to reduce the
size of data portions of the transfer.
rsync ‐avz foo:src/bar/ /data/tmp
A trailing slash on the source changes this behavior to avoid creating
an additional directory level at the destination. You can think of a
trailing / on a source as meaning "copy the contents of this directory"
as opposed to "copy the directory by name", but in both cases the at‐
tributes of the containing directory are transferred to the containing
directory on the destination. In other words, each of the following
commands copies the files in the same way, including their setting of
the attributes of /dest/foo:
rsync ‐av /src/foo /dest
rsync ‐av /src/foo/ /dest/foo
Note also that host and module references don’t require a trailing slash
to copy the contents of the default directory. For example, both of
these copy the remote directory’s contents into "/dest":
rsync ‐av host: /dest
rsync ‐av host::module /dest
You can also use rsync in local‐only mode, where both the source and
destination don’t have a ’:’ in the name. In this case it behaves like
an improved copy command.
Finally, you can list all the (listable) modules available from a par‐
ticular rsync daemon by leaving off the module name:
rsync somehost.mydomain.com::
COPYING TO A DIFFERENT NAME
When you want to copy a directory to a different name, use a trailing
slash on the source directory to put the contents of the directory into
any destination directory you like:
rsync ‐ai foo/ bar/
Rsync also has the ability to customize a destination file’s name when
copying a single item. The rules for this are:
o The transfer list must consist of a single item (either a file or
an empty directory)
o The final element of the destination path must not exist as a di‐
rectory
o The destination path must not have been specified with a trailing
slash
Under those circumstances, rsync will set the name of the destination’s
single item to the last element of the destination path. Keep in mind
that it is best to only use this idiom when copying a file and use the
above trailing‐slash idiom when copying a directory.
The following example copies the foo.c file as bar.c in the save dir
(assuming that bar.c isn’t a directory):
rsync ‐ai src/foo.c save/bar.c
The single‐item copy rule might accidentally bite you if you unknowingly
copy a single item and specify a destination dir that doesn’t exist
(without using a trailing slash). For example, if src/*.c matches one
file and save/dir doesn’t exist, this will confuse you by naming the
destination file save/dir:
rsync ‐ai src/*.c save/dir
To prevent such an accident, either make sure the destination dir exists
or specify the destination path with a trailing slash:
rsync ‐ai src/*.c save/dir/
SORTED TRANSFER ORDER
Rsync always sorts the specified filenames into its internal transfer
list. This handles the merging together of the contents of identically
named directories, makes it easy to remove duplicate filenames. It can,
however, confuse someone when the files are transferred in a different
order than what was given on the command‐line.
If you need a particular file to be transferred prior to another, either
separate the files into different rsync calls, or consider using --de‐
lay‐updates (which doesn’t affect the sorted transfer order, but