Slashes and the rsync command Slashes and the rsync command unix unix

Slashes and the rsync command


It's described in the rsync(1) manpage.

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 attributes of the containing directory are transferred to the containing directory on the destination. In other words, each of the follow‐ ing commands copies the files in the same way, including their setting of the attributes of /dest/foo:

rsync -av /src/foo /destrsync -av /src/foo/ /dest/foo

As to the destination, I don't think it has any major consequences. There is a difference if the source is a file and destination doesn't exist — the command

rsync SRC DEST

will make a copy of SRC called DEST, whereas

rsync SRC DEST/

will create directory DEST and copy the SRC file into it.


I tested it with rsync 3.1.3 on Arch Linux, the results are below:

1. rsync -avPzu test  login@remote:/home/login/test   "test" directory is copied inside of existing "test" on remote (structure is then test/test/...)2. rsync -avPzu test  login@remote:/home/login/test/  same as above3. rsync -avPzu test/ login@remote:/home/login/test   content of "test" directory is synchronized with the remote "test" directory4. rsync -avPzu test/ login@remote:/home/login/test/  same as above5. rsync -avPzu test  login@remote:/home/login/       same as above6. rsync -avPzu test  login@remote:/home/login        same as above

The methods 3-6 are the correct ones in this case, contrary to the accepted answer.


keep the slashes on the source, and remove them from the destination. Like this:

alias syncDirectories1 = 'rsync -tvur name@host:/Users/me/directory/ /Users/me/directory'alias syncDirectories2 = 'rsync -tvur /Users/me/directory/ name@host:/Users/me/directory'