Junior
What does the 'rsync' command do?
sobes.tech AI
Answer from AI
The rsync command is used for synchronizing files and directories between two locations, minimizing the amount of data transferred by copying only the changed parts of files.
Key features:
- Incremental copying: Copies only the parts of files that have changed since the last copy.
- Remote synchronization: Can copy files between local and remote systems (via SSH or its own protocol).
- Preservation of attributes: By default, preserves permissions, owners, groups, and timestamps.
- Support for symbolic links: Can correctly handle symbolic links.
- Mirror mode: The
--deleteoption deletes files in the target directory that are not in the source, making an exact copy. - Compression: The
-zoption enables data compression during transfer.
Main syntax:
# Synchronize local folder1 with local folder2
rsync [options] /path/to/source/folder1 /path/to/destination/folder2
# Synchronize local folder with remote
rsync [options] /path/to/source/folder user@remote_host:/path/to/destination/folder
# Synchronize remote folder with local
rsync [options] user@remote_host:/path/to/source/folder /path/to/destination/folder
Example options:
| Option | Description |
|---|---|
-a |
Archive mode (recursive, preserves attributes). |
-v |
Verbose output. |
-z |
Compression during transfer. |
--delete |
Delete files in the destination folder that are not in the source. |
-P |
Combination of --partial and --progress (shows progress). |
Used for backup, data synchronization between servers, and file migration.