Copy files to remote machine

-a
archive mode
recursive into directories
preserve file permissions
preserve symlinks as symlinks
-v
verbose
-z
compress during transfer

rsync -azv src user@hostname:dest/folder

Note:

  • Use -n for a dry fun.
  • user@hostname can be shortened with .ssh config
  • can use wildcards in source i.e. rsync src/*.js [dest]
  • can show progress with --progress

Specify ssh configuration information

-e 'ssh [options]' allows you to customize ssh options such as port or path to ssh key.

rsync -azve 'ssh -i ~/.ssh/id_rsa' src user@hostname:dest/folder

Copy files from remote machine to local machine

rsync [options] user@host:dest/folder local/folder

Other Options

delete extraneous files in destination

Use --delete

exclude files and folders from rsync

--exclude=<Pattern> i.e. --exclude=*.sh

or to keep exclusions in a separate file:

--exclude-from=<file>

i.e. with --exclude-from=./exclusions

in file called exclusions:

node_modules
.git
*/nested_folder_somewhere
wp-config.php
*.sh