How do I use rsync to copy and synchronize files?

rsync is a tool that you can use to copy files between your computer and a remote server.

rsync can also be used to copy files directly between remote servers, bypassing your computer entirely.

Copy files between your computer and a remote server

To copy files from your computer to a remote server using rsync, run:

rsync -av --info=progress2 FILES USERNAME@SERVER-IP:REMOTE-PATH

Replace FILES with the files you want to copy to the remote server. Alternatively, you can specify a directory.

Replace USERNAME with your username on the remote server.

Replace SERVER-IP with the IP address of the remote server.

Replace REMOTE-PATH with the directory into which you want to copy files.

In the below example, rsync was used to copy the local directory rsync_example_dir, containing a single empty file named EXAMPLE_FILE, into the home directory of the user ubuntu on a remote server with the IP address 146.235.208.193.

$ rsync -a --progress rsync_example_dir [email protected]:~
sending incremental file list
rsync_example_dir/
rsync_example_dir/EXAMPLE_FILE
              0 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=0/2)

Copy files directly between remote servers

To copy files directly between remote servers using rsync, first SSH into the server you want to copy files from by running:

ssh -A USERNAME-1@SERVER-IP-1

Replace SERVER-IP-1 with the IP address of the server you want to copy files from, referred to below as Server 1.

Replace USERNAME-1 with your username on Server 1.

Then, on Server 1, run:

rsync -av --info=progress2 FILES USERNAME-2@SERVER-IP-2:REMOTE-PATH

Replace SERVER-IP-2 with the IP address of the server you want to copy files to, referred to below as Server 2.

Replace FILES with the files (or directory) you want to copy to Server 2.

Replace USERNAME-2 with your username on Server 2.

Replace SERVER-IP-2 with the IP address of Server 2.

Replace REMOTE-PATH with the directory into which you want to copy files.


Last modified January 31, 2024: Delete script that's no longer useable (af5a731)