Skip to content

Instantly share code, notes, and snippets.

@gnzsnz
Last active October 21, 2022 08:54
Show Gist options
  • Save gnzsnz/d5f993d4663067b43c732272ed2d31e5 to your computer and use it in GitHub Desktop.
Save gnzsnz/d5f993d4663067b43c732272ed2d31e5 to your computer and use it in GitHub Desktop.
A quick and dirty cheat sheet for rsync

rsync cheat sheet

rsync -rtva -e ssh --delete Documents/Work user@hostname:~/Documents

  • r recurisve

  • t preserve times

  • v verbose

  • a archive - preserve ownership permisions, timestamp, same as -rlptgoD

  • e ssh - specify the remote shell to use

  • delete - delete extraneous files from dest dirs

  • n dry-run

  • z compress data during transfer

rsync -zav Documents/Work user@hostname:~/Documents

Trailing slash

rsync -avz foo:src/bar /data/tmp

This would recursively transfer all files from the directory src/bar on the machine foo into the /data/tmp/bar directory on the local machine.

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 con‐tents 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment