奇客の遊園地

Copy Data with rsync on Ubuntu

Rsync (Remote sync) is a useful synchronization tool for copying and synchronizing files and directories in local and remote Linux systems. You can synchronize files between two directories on the same computer, between the directories in two systems on the same network and between two directories on the remote system.

In this article, I will describe some common use cases for rsync in Linux.

Installing Rsync on Ubuntu

Rsync is pre-installed with some of the Linux distributions. If it is not pre-installed, you can install it using the below command:

sudo apt install rsync

Using Rsync

The basic syntax of rsync is:

# rsync [options] [source] [destination]

In options, you can specify a variety of parameters.

Copy files locally

To copy all the files from a source directory to the destination directory, enter the below command:

Copy files from local to a remote system

This command copies the content of the local /var/www folder to the folder /var/www of the system on IP 192.168.0.100. It uses the user ‘root’ to log into the remote system.

Copying Files Based on Size

You can also specify the maximum size of the file that can be copied using rsync. Let’s say, in this case, I am specifying the maximum size to 0.2K. Files with size larger than this will not be copied to /home/tin/Desktop/data.