Linux rsync Command: Synchronize Files and Directories
rsync copies files and efficiently synchronizes changes between local or remote locations. It is useful for repeated transfers of large amounts of data, but if the destination path and delete options are incorrectly specified, data can be lost.
What is the rsync command?
Basically, it selects the transfer targets by comparing size and modification times. -a is archive mode, which combines recursive copying and preservation of key metadata. source/ copies the contents of a directory, while source copies the directory itself to the destination; this difference is important. For SSH-style remote paths, use user@host:path.
Basic syntax
rsync [options] source destination
The installed implementation and options may vary depending on the distribution. Check the description for your current system with man rsync.
Examples
Preview before actual changes
Check the destination path and copy range with the output list.
rsync -av --dry-run project/ backup/project/
Synchronizing local directories
Copies the contents inside the source directory to the destination.
rsync -av project/ backup/project/
Remote transfer via SSH
rsync must also be installed on the remote, and change the account/path to the actual values.
rsync -av project/ alice@server.example.com:/home/alice/project/
Preview before actual copy
rsync --dry-run shows the list of files scheduled to be changed but does not actually copy the data. The directory structure created in the destination varies depending on whether there is a trailing slash.
rsync -av --dry-run source/ backup/
Example output when source/ contains notes.txt but the destination does not:
sending incremental file list notes.txt
This command means that the contents inside the source directory, not the directory itself, will be synchronized to backup/. If you add --delete, files that exist only in the destination may be deleted, so be sure to review the --dry-run results. After actual execution, verify important files by file count, size, or checksum.
-a combines recursive copying with preservation of several metadata fields, but it is not a complete backup of every ACL, extended attribute, or hard link. Choose additional options based on the required metadata, destination filesystem, and permissions. For important data, test restoring from the destination too.
Main Options and Format
| Options/Format | Description |
|---|---|
-a |
This is archive mode, which combines recursive copy and preservation of main attributes. |
-v |
Shows detailed items being processed. |
-n, --dry-run |
Prints the work plan without making actual changes. |
--delete |
Deletes destination files that are not in the source. Review in advance is required. |
--exclude=pattern |
Excludes files matching the specified pattern from the transfer. |
-e 'ssh -p port' |
Specifies the remote shell command and port. |
Precautions when using
--delete actually removes the target files. Check the trailing slashes on the source and destination paths and the filter rules, and review the deletion list with --dry-run. rsync is not a backup solution itself, and mistakes or corruption in the source can also be replicated. Remote transfers usually require rsync on both sides, and archive mode does not preserve ACLs or extended attributes completely.
Frequently Asked Questions
What is the difference between source and source/ in rsync?
source/ copies the contents of that directory, while source copies the directory itself under the destination.
Official Documentation
You can check the exact behavior of options and implementation differences in the official rsync documentation.









