Logo

How to Install and Use rsync on ubuntu 22.04

Jul 01, 2023

To install and use rsync on Ubuntu 22.04, you can follow these steps:

Installing rsync

Step 1 : Update the package index:

sudo apt update

Step 2 : Install rsync:

sudo apt install rsync

Copying files locally

To copy files or directories within your local machine using rsync, use the following command:

rsync -avzh /path/to/source /path/to/destination

Replace /path/to/source with the source file or directory you want to copy, and /path/to/destination with the destination directory where you want to place the copied files.

Example:

rsync -avzh /home/user/documents /backup/documents

This command will copy the contents of the /home/user/documents directory to the /backup/documents directory.

Uploading to a remote server

To upload files or directories from your local machine to a remote server using rsync, use the following command:

rsync -avzh /path/to/source user@remote:/path/to/destination

Replace /path/to/source with the local source file or directory, user with the username of the remote server, remote with the IP address or domain name of the remote server, and /path/to/destination with the path on the remote server where you want to upload the files.

Example:

rsync -avzh /backup/documents user@remote:/home/user/documents

This command will upload the contents of the /backup/documents directory to the /home/user/documents directory on the remote server.

Downloading from a remote server

To download files or directories from a remote server to your local machine using rsync, use the following command:

rsync -avzh user@remote:/path/to/source /path/to/destination

Replace user with the username of the remote server, remote with the IP address or domain name of the remote server, /path/to/source with the remote source file or directory, and /path/to/destination with the local destination directory where you want to save the downloaded files.

Example:

rsync -avzh user@remote:/home/user/documents /backup/documents

This command will download the contents of the /home/user/documents directory from the remote server to the /backup/documents directory on your local machine.

You can now use rsync for copying files locally, uploading to a remote server, and downloading from a remote server based on your specific needs.

Recommended