rsync command with and without slash

Although rsync is a very popular file and directory synchronization tool, there is a difference in behavior depending on whether or not the SRC is terminated with a trailing slash when the command is used. This point is often a source of confusion for beginners.

It is easy to understand that the presence or absence of the SRC slash in rsync can be thought of as the same as the difference between mv SRC DEST andmv SRC/* DEST. In other words, it can be thought of as a slash followed by an omitted *.

Specifically, if there is a slash, the contents of the SRC directory are copied; if there is no slash, the SRC directory itself is copied.

On the other hand, the presence or absence of a slash in the destination directory has basically no effect. As an example, rsync -av src/ dst/src andrsync -av src/ dst/src/ work the same.

Understanding these subtle differences will help you avoid copying in unintended directory structures and make more effective use of rsync.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top