bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Bash/Networking
Bash•Networking

Bash rsync Command - Remote (and local) File-copying

Using the rsync Command

The rsync command is used to efficiently transfer and synchronize files across computer systems, by checking the timestamp and size of files.

Basic Usage

To synchronize a directory to a remote host, use rsync -avz source user@hostname:/path :

Example

rsync -avz /local/dir/ user@example.com:/remote/dir/

Understanding Rsync Output

The output of the rsync command can vary depending on the options used. Here are some common elements:

  • File List: Lists the files being transferred.
  • Transfer Progress: Shows the progress of each file transfer.
  • Compression Ratio: Indicates the effectiveness of compression if used.
  • Speed: The speed at which files are being transferred.

Rsync Options Overview

Here are some common options you can use with the rsync command:

  • -a - Archive mode
  • -v - Increase verbosity
  • -z - Compress file data
  • --delete - Delete extraneous files
  • -r - Recurse into directories
  • -u - Skip files that are newer on the receiver
  • --progress - Show progress during transfer

Option: -a (Archive Mode)

The -a option enables archive mode, which preserves permissions, times, symbolic links, and more. It's like a combination of several options.

Example: Archive Mode

rsync -a /local/dir/ user@example.com:/remote/dir/

Option: -v (Verbose)

The -v option increases verbosity, providing detailed output of the rsync process.

Example: Verbose Output

rsync -av /local/dir/ user@example.com:/remote/dir/

Option: -z (Compression)

The -z option compresses file data during transfer, which can speed up the transfer process.

Example: Enable Compression

rsync -az /local/dir/ user@example.com:/remote/dir/

Option: --delete

The --delete option deletes files from the destination that are not present in the source.

Example: Delete Extraneous Files

rsync -avz --delete /local/dir/ user@example.com:/remote/dir/

Option: -r (Recursive)

The -r option allows rsync to recurse into directories, copying all files and subdirectories.

Example: Recursive Copy

rsync -ar /local/dir/ user@example.com:/remote/dir/

Option: -u (Update)

The -u option skips files that are newer on the receiver, avoiding overwriting newer files.

Example: Skip Newer Files

rsync -avu /local/dir/ user@example.com:/remote/dir/

Option: --progress

The --progress option shows progress during transfer, providing detailed information about the transfer status.

Example: Show Progress

rsync --progress /local/dir/ user@example.com:/remote/dir/

Troubleshooting Common Issues

Common issues with rsync include "Permission Denied" or "Connection Timeout". Here are some troubleshooting tips:

  • Permission Denied: Ensure you have the correct permissions on both the source and destination directories. Check user permissions and SSH key access.
  • Connection Timeout: Verify network connectivity and ensure the remote server is reachable. Check firewall settings and SSH configurations.

Previous

Bash scp Command - Secure Copy

Next chapter

File Compression

Start with Bash zip Command - Package and compress (archive) files

This chapter

Overview
6

Lessons

19m

Read time

1. Bash ping Command - Send Request to Network Hosts2. Bash curl Command - Transfer a URL3. Bash wget Command - Non-Interactive Network Downloader4. Bash ssh Command - OpenSSH SSH Client5. Bash scp Command - Secure Copy6. Bash rsync Command - Remote (and local) File-copying

On this page

Using the rsync CommandBasic UsageUnderstanding Rsync OutputRsync Options OverviewOption: -a (Archive Mode)Example: Archive ModeOption: -v (Verbose)Example: Verbose OutputOption: -z (Compression)Example: Enable CompressionOption: --deleteExample: Delete Extraneous FilesOption: -r (Recursive)Example: Recursive CopyOption: -u (Update)Example: Skip Newer FilesOption: --progressExample: Show ProgressTroubleshooting Common Issues