Transfer files either to or from a remote host. Can transfer single files, or multiple files matching a pattern.
# To transfer file from local to remote host:
rsync <path/to/local_file> <remote_host>:<path/to/remote_directory>
# To transfer file from remote host to local:
rsync <remote_host>:<path/to/remote_file> <path/to/local_directory>
# To transfer file in [a]rchive (to preserve attributes) and compressed ([z]ipped) mode with [v]erbose and [h]uman-readable [P]rogress:
rsync -azvhP <path/to/local_file> <remote_host>:<path/to/remote_directory>
# To transfer a directory and all its children from a remote to local:
rsync -r <remote_host>:<path/to/remote_directory> <path/to/local_directory>
# To transfer directory contents (but not the directory itself) from a remote to local:
rsync -r <remote_host>:<path/to/remote_directory>/ <path/to/local_directory>
# To transfer a directory [r]ecursively, in [a]rchive to preserve attributes, resolving contained soft[l]inks , and ignoring already transferred files [u]nless newer:
rsync -rauL <remote_host>:<path/to/remote_directory> <path/to/local_directory>
# To transfer file over SSH and delete remote files that do not exist locally:
rsync -e ssh --delete <remote_host>:<path/to/remote_file> <path/to/local_file>
# To transfer file over SSH using a different port than the default and show global progress:
rsync -e 'ssh -p <port>' --info=progress2 <remote_host>:<path/to/remote_file> <path/to/local_file>
# ---
# copy files from remote to local, maintaining file propertires
# and sym-links (-a), zipping for faster transfer (-z), verbose (-v).
$ rsync -avz host:file1 :file1 /dest/
$ rsync -avz /source host:/dest
# Copy files using checksum (-c), rather than time, to detect if the file
# has changed. Useful for validating backups.
$ rsync -avc /source/ /dest/
# --archive archive mode
# --checksum skip based on checksum, not mod-time and size
# --progress show progress during transfer
# --delete extraneous files from dest dirs
# --delete-excluded also delete excluded files from dest dirs
# --force force deletion of dirs even if not empty
# --ignore-errors delete even if there are I/O errors
# --human-readable output numbers in a human-readable format
# -- exclude exludes file(s) from syncing
$ rsync --archive \
--checksum \
--progress \
--delete \
--delete-excluded \
--force \
--ignore-errors \
--human-readable \
--exclude '*.pyc' \
--exclude '.DS_Store' \
<source_dir> <dest_dir>