The rsync (remote synchronization) is a command used on Unix-like systems for copying and synchronizing files and directories between two machines. It uses the delta transfer algorithm in which first time it copies the whole file or a directory from source to the destination computer, next time it copies only the changed blocks and byte to the destination.
In this article, you will see the usage of rsync command along with some examples.
- 1 How to install rsync in a Linux system
- 2 How to use rsync command in Linux
- 3 Usage of rsync command in Linux
- 4 Conclusion
How to install rsync in a Linux system
In most of the distribution, it comes preinstalled. If it is not in your system then on the basis of distribution, use one of the given commands in your system.
In Ubuntu/ Linux Mint/ Debian, use –
sudo apt install rsync
If you are using CentOS/ RHEL then use –
sudo yum install rsync
For Arch Linux or Manjaro, use –
sudo pacman -S rsync
Once it gets installed you can verify the installation by using –
How to use rsync command in Linux
The basic syntax of using rsync command in Linux is given below.
rsync [Options] Source Destination
Where you can find a detailed list of options on rsync command man page. The source is the machine or host from which the file or directory is to be copied or synced and the destination is the location where synchronization will take place.
Usage of rsync command in Linux
The examples and use cases of the Linux rsync command are given below.
Copy/Sync file or directory locally
The most basic use of rsync command is to copy files or directories from one location to another location in a Local system. You can see the example below.
rsync -a ~/Downloads/eclipse-inst-jre-linux64.tar.gz /home/lalit
Here eclipse file will get copied from the
Downloads directory to
/home/lalit. You can see the output of this command in the given image.
Optionally you can add the
--progress option with this command to see the progress.
To copy a directory locally from one location to another use –
rsync -a ~/Downloads/eclipse-installer /home/lalit
In the above example directory, eclipse-installer will get copied from
/home/lalit If the destination directory does not exist this command will create a new directory at the given location.
Copy/Sync file or directory from local to the remote machine
To copy or sync a file from your system to a remote system you need to use the command like it is given below.
rsync -a ~/Downloads/eclipse-inst-jre-linux64.tar.gz [email protected]:/home/lalit/Desktop
This will copy/sync the eclipse file from the
Download directory on the local system to
/home/lalit/Desktop on the remote system.
Similarly, you can use the given command if you want to copy/sync a directory from the local to the remote system.
rsync -a ~/Downloads/eclipse-installer [email protected]:/home/lalit/Desktop
Copy/sync a file or directory from a remote to the local machine
If you want to copy/sync a file or directory from a remote system to your local machine then you need to use the command like it is given below.
sudo rsync -a [email protected]:/home/lalit/teamviewer_amd64.deb /opt/media/
To copy/sync some files or directories you may need to have root permission. This command will copy/sync
teamviewer_amd64.deb file from remote to a local system.
You can see the output of the above command in the given image.
Similarly, you can mention the directory name instead of a filename to copy/sync a directory from the remote machine to a local computer.
The rsync command copies files or directories efficiently and it is faster than tools like scp (secure copy). Now if you have any queries then write us in the comments below.