C.W.K.
Stream
Lesson 05 of 12 · published

rsync over SSH (and the Trailing Slash)

~15 min · rsync, ssh, trailing-slash

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

Same syntax, SSH transport

rsync uses SSH by default for remote transfers — same key, same agent, same ~/.ssh/config. The remote side just needs rsync installed, which it almost always is. You can pass SSH options through with -e.

The trailing slash — the #1 source of rsync confusion

This single rule causes more rsync sadness than any other:

  • rsync -av project/ dest/ — copies the contents of project/ into dest/.
  • rsync -av project dest/ — copies the directory itself into dest/, ending up at dest/project/.

The trailing slash on project/ means "the contents of" — like the shell glob project/* but including dotfiles. No trailing slash means "this directory as a whole."

When in doubt, --dry-run first.

Code

Push, pull, and the slash·bash
# Push: laptop → office
rsync -avz --progress ./project/ office:/home/you_username/project/

# Pull: office → laptop
rsync -avz --progress office:/home/you_username/project/ ./project/

# Specify SSH options (e.g. non-default port — though ~/.ssh/config is cleaner)
rsync -avz -e "ssh -p 2222" ./files/ host:/dest/

# Trailing slash demonstration
# WITH slash on source — copies CONTENTS
rsync -av project/ host:/dest/    # → /dest/file1, /dest/file2

# WITHOUT slash — copies the DIRECTORY itself
rsync -av project host:/dest/     # → /dest/project/file1, /dest/project/file2

External links

Exercise

On any test path, run both rsync -avn project/ /tmp/x/ and rsync -avn project /tmp/x/ (note the dry-run) and compare the listed paths. The first puts files at /tmp/x/foo, the second at /tmp/x/project/foo. This is the muscle memory you want — feel the slash, never guess it.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.