How to use rsync to transfer files between Linux machines?

Published on Aug. 22, 2023, 12:18 p.m.

You can use the rsync command to transfer files between Linux machines. Here’s an example command for transferring a directory from a local machine to a remote machine:

rsync -avz /path/to/local/dir user@remote:/path/to/remote/dir

This command specifies the source directory (/path/to/local/dir), the destination directory on the remote machine (user@remote:/path/to/remote/dir), and uses the avz options to archive, preserve permissions and timestamps, compress data, and show progress during the transfer. You can replace user and remote with the appropriate remote machine credentials and IP address respectively.

If you want to transfer files from a remote machine to a local machine, you can use the following command:

rsync -avz user@remote:/path/to/remote/dir /path/to/local/dir

This command specifies the source directory on the remote machine (user@remote:/path/to/remote/dir), the destination directory on the local machine (/path/to/local/dir), and uses the same options as before.

Make sure you have rsync installed on both machines and that you have appropriate permissions to access the directories you’re trying to transfer.

Tags: