The rsync
command is a powerful tool used for synchronizing files and directories between two locations, either on the same machine or across different machines. It is particularly useful for backups and mirroring, as it only transfers the differences between the source and the destination, making it efficient in terms of both speed and bandwidth.
The basic syntax of the rsync
command is as follows:
rsync [options] [source] [destination]
Here are some commonly used options with rsync
:
-a
: Archive mode; it preserves permissions, timestamps, symbolic links, and other attributes.-v
: Verbose; provides detailed output of the transfer process.-z
: Compress; compresses file data during the transfer for faster transmission.-r
: Recursive; copies directories recursively.--delete
: Deletes files in the destination that are not present in the source.-n
: Dry run; shows what would be done without actually making any changes.rsync -av source.txt destination.txt
rsync -av /path/to/source/ /path/to/destination/
rsync -avz /path/to/source/ user@remote_host:/path/to/destination/
rsync -av --delete /path/to/source/ /path/to/destination/
rsync -avn /path/to/source/ /path/to/destination/
-n
option for a dry run before executing a command that modifies files, especially when using --delete
.-z
option to speed up the process by compressing the data.