Sync source_directory/
directory to destination_directory/
:
rsync -avh source_directory/ destination_directory/
Here, -a
, --archive
is a shortcut option, equivalent to -rlptgoD
. It means to sync files and directories recursively and preserve file metadata (permissions, timestamps, etc.).
v
, --verbose
means to output verbose information.h
, --human-readable
means to display file sizes in a human-readable way.Sync local source_directory/
directory to destination_directory/
on a remote host:
rsync -avh source_directory/ user@remote_host:/path/to/destination_directory/
Here, user
is the username of the remote host.
Sync local source_directory/
directory to destination_directory/
on a remote host via SSH:
rsync -avh -e 'ssh -p port_number' source_directory/ user@remote_host:/path/to/destination_directory/
Here, port_number
is the port number of the SSH server.
Delete files not present at the destination during the sync:
rsync -avh --delete source_directory/ destination_directory/
Exclude specific files and directories during the sync:
rsync -avh --exclude 'file.txt' --exclude 'directory/' source_directory/ destination_directory/
Compress data during transfer to reduce bandwidth usage:
rsync -avh -z source_directory/ destination_directory/
Here, -z
, --compress
enables compression during transfer.
Limit bandwidth usage to 100 KB/s during transfer:
rsync -avh --bwlimit=100 source_directory/ destination_directory/
Perform a test run without actual transfer:
rsync -avh --dry-run source_directory/ destination_directory/
Display progress during transfer:
rsync -avh --progress source_directory/ destination_directory/