Trailing slash in rsync

RSync has some different and confusing behavior depending on whether you put a trailing slash on the source directory or not.

  • No trailing slash on source directory: this copies the source directory itself as a subdirectory into the destination directory.

For example:

$ rsync -a /some/path/foobar .
$ ls
foobar/
  • Trailing slash on source directory: this copies the contents inside source directory into the destination directory.

For example:

$ rsync -a /some/path/foobar/ .
$ ls
content.txt
of.txt
foobar.txt

You do not see such confusing behavior with cp or mv. I guess rsync has this because it is usually used for synchronizing the contents of two directories but it is also sometimes used to copy over directories.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s