
Linux Command Line
Rsync is a powerful command-line tool for synchronizing files and directories between different locations. It is widely used in Linux and UNIX-based systems for backups, file transfers, and data replication. In this guide, we will explore the basics of the rsync command, when to use it, and how to use it with some examples.
When to Use Rsync
Rsync is an ideal tool for synchronizing files and directories between different locations, such as between local and remote servers, or between a local machine and a backup drive. It is especially useful for:
- Backing up important files and directories
- Synchronizing files and directories between multiple machines
- Transferring large files over a network
- Mirroring a remote directory to a local machine
How to Use Rsync
The basic syntax of the rsync command is as follows:
rsync [options] [source] [destination]
Here are some examples of how to use rsync:
- To synchronize the contents of a local directory “~/documents” with a remote directory “/backup/documents” over SSH, use the following command:
rsync -avz -e ssh ~/documents/ user@remote:/backup/documents/
- To mirror a remote directory “~/documents” to a local directory “/backup/documents”, use the following command:
rsync -avz user@remote:~/documents/ /backup/documents/
- To backup a directory “/etc” to a local directory “/backup”, use the following command:
rsync -avz /etc/ /backup/
Options
- -a : Archive mode (copies files and directories recursively, preserving permissions, timestamps, and symlinks)
- -v : Verbose mode (shows progress and detailed information)
- -z : Compress file data during the transfer
- -e : Specify the remote shell to use (e.g. ssh)
Rsync is a powerful command-line tool that can be used for a variety of file synchronization tasks. It is particularly useful for backups, file transfers, and data replication. By mastering the basics of the rsync command, you can easily synchronize files and directories between different locations on Linux.
See our list of 75 Linux commands you should know about.