rsync Linux Command
Efficiently syncs files and directories between two locations (local or remote).
What does rsync do?
Efficiently syncs files and directories between two locations (local or remote).
Syntax
rsync [options] source destinationPractical example
rsync -avz /local/dir user@remote:/backup/Questions about rsync
How do I sync a directory with rsync?
Use `rsync -avz /source/ /destination/` to sync directories. The trailing slash on source matters: `/source/` syncs contents, `/source` syncs the directory itself.
What does rsync -avz mean?
`-a` is archive mode (preserves permissions, times, etc.), `-v` is verbose, `-z` compresses data during transfer.
How do I sync to a remote server with rsync?
Use `rsync -avz /local/dir user@remote:/remote/path/` to sync to a remote server over SSH.
How do I do a dry run with rsync?
Use `rsync -avn /source/ /dest/` to show what would be transferred without actually doing it.
How do I delete files at the destination?
Use `rsync -avz --delete /source/ /dest/` to delete files at the destination that don't exist at the source.
How do I resume an interrupted rsync?
Use `rsync -avzP /source/ /dest/` with the `-P` flag which combines `--progress` and `--partial` for resuming.
How do I exclude files from rsync?
Use `rsync -avz --exclude='*.log' /source/ /dest/` to exclude files matching a pattern.
How do I see rsync progress?
Use `rsync -avzP /source/ /dest/` to see progress for each file and overall transfer progress.
Related Remote Access Commands
scpSecurely copies files between local and remote hosts over SSH.
ftpTransfers files to and from a remote host using the File Transfer Protocol.
sshConnects securely to a remote machine via the SSH protocol.
sftpSecurely transfers files over SSH (interactive FTP-like interface).
ssh-copy-idCopies your SSH public key to a remote server for key-based authentication.
telnetConnects to a remote host via the Telnet protocol (unencrypted — prefer SSH).