• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

The Linux Rsync Command: Usage and Practical Examples

CJ Saathoff

Published on: June 4, 2024

Categories: Linux Command Line 0

Unix Like systems including Linux are composed of many files and folders. So it isn’t surprising that there are many times when synchronizing files and directories is needed. This is where the rsync command in Linux shines as it’s used to transfer data between two locations. It supports transferring files between local and remote directories. The rsync command is my go-to command line tool for transferring many files.

In this blog post, we will transfer files with this extremely flexible tool, having just the right options for your file sync needs.

Table of Contents
  • Installing Rsync
  • Basic Syntax
  • Flags And Options
  • Examples
    • Local To Local
    • Setting Ownership And Permissions
    • Do A Dry Run
    • Local To Remote
    • Local To Remote With Bandwidth Limit
    • Remote To Local
    • Remote To Local Using Custom Port
    • Show Stats After Transfer
    • Sync Files Smaller Than 1GB And Larger Than 1MB
    • Update Files And Directories
    • Ignore Existing Files
    • Delete Files After Transfer
  • Tips And Tricks
  • Conclusion
  • Additional Links

Installing Rsync

On most Linux Distributions the package is rsync so for example with dnf and apt the install command would be.

dnf install rsync
apt install rsync

Basic Syntax

The basic syntax for rsync is as follows:

rsync [options] source destination

If local it will be the path of the file or directory you want to sync.

If transferring from or to a remote location this will be in the format user@host:/path/to/destination.

Flags And Options

The options for rsync are vast, after going through them here are the ones I believe everyone should know.

–bwlimit=RATE allows you to set a bandwidth limit on transfers

–human-readable, -h output numbers in a human-readable format

–progress show progress during the transfer

–max-size=SIZE the maximum size of a file you want to transfer

–min-size=SIZE the minimum size of a file you want to transfer

–remove-source-files sender removes synchronized files (non-dir)

–dry-run, -n perform a trial run with no changes made

–compress, -z compress data during the transfer

–perms, -p preserve source permissions

–quiet, -q suppress non-error messages

–checksum, -c skip based on checksum, not mod-time & size

–archive, -a archive mode is equivalent of -rlptgoD

–recursive, -r recurse into directories

–update, -u skip files that are newer on the destination

–ignore-existing skip updating files that exist on the destination

–verbose, -v increases the verbosity of the output

–stats when the command finishes transfer statistics will be displayed

–delete delete extraneous files from the destination

–chmod=CHMOD allows for setting permissions during the transfer

–chown=USER:GROUP allows for setting ownership during the transfer

If you don’t see a particular option in this section review the man page using the bellow command or refer to an online version.

man rsync

Examples

In the below examples, the flags discussed are shown in practical examples. All the examples include multiple flags, most commonly the v (verbose output) and h (human-readable format) only affect the output and I recommend using them.

Local To Local

rsync -ahv /source/path/ /destination/path

If you need to copy files and directories from one place to another locally use this command.

Setting Ownership And Permissions

rsync -vh --chown=user:group --chmod=755 /source/path/ /destination/path

Instead of using the archive flag, we set the desired ownership and file permissions manually.

Do A Dry Run

rsync -avh --dry-run /source/path/ /destination/path

In this example, nothing is being transferred but the output can be used to confirm the command is structed correctly.

Local To Remote

rsync -avhz /source/path/ [email protected]:/destination/path

Transfers from local to remote machine using compression.

Local To Remote With Bandwidth Limit

rsync -avhz --bwlimit=100M /source/path/ [email protected]:/destination/path

Transfers from remote to local using compression and a bandwidth limit.

Remote To Local

rsync -avhz [email protected]:/source/path/ /destination/path

Remote sync from remote to local using compression.

Remote To Local Using Custom Port

rsync -avhz -e 'ssh -p <port-number>' [email protected]:/source/path/ /destination/path

Transfers from remote to local using compression over a non-standard ssh port.

Show Stats After Transfer

rsync --stats -avh /path/to/source/ /path/to/destination/

Update files that are newer and show transfer stats

Sync Files Smaller Than 1GB And Larger Than 1MB

rsync --max-size=1G --min-size=1M -avh /path/to/source/ /path/to/backup/

This example sets a maximum and minimum file size for the files to transfer.

Update Files And Directories

rsync -avhu /path/to/source/ /path/to/destination/

Files that are newer in the source will overwrite the older versions, in addition, files that don’t exist on the destination will be copied over.

Ignore Existing Files

rsync --ignore-existing -avh /path/to/source/ /path/to/destination/

All the files that already exist are skipped and any missing files from the source are copied over.

Delete Files After Transfer

rsync -ahv --remove-source-files /source/path/ /destination/path

In this example, the command removes only the files from the source after transfer.

Tips And Tricks

  • Always do a dry run using the verbose flag first to confirm everything works as expected.
  • If transferring between a remote system consider using a bandwidth limit.
  • If transferring between a remote system consider using compression.
  • If using a delete or remove be certain you understand the flag before using.
  • Unless you know the permission needs to be different use archive mode to preserve them.
  • If you need to filter files consider using rsync together with the find command.
    • Although rsync does have filtering capabilities my recommendation is to couple it with the find command like the example below:find source -type f -exec rsync -avh --progress {} destination ;

In this example, the find command is being used to filter out only the files and transfer them

Conclusion

In conclusion, we started with installing the rsync command and touched on syntax and options. From there, I have included many different examples using the options which I feel everyone should know. Whether you need remote syncor just need to sync directories on your local machine rsync has got you covered.

Additional Links

Done reading and want additional resources, why not check out these?

  • Other Command Posts
  • Rsync Offical Site
  • Rsync Wikipedia Page
CJ Saathoff

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.

Related Posts

Dealing with Cron Job Logs in Linux

Cron job logs keep track of which cron jobs run, and their details. This helps with troubleshooting and performance management.

How to Use Git Rebase Interactive to Manage Commits

As a project progresses, commits can get messy. The git rebase interactive feature allows you to keep a clean commit history.

How to Use Process Substitution in Bash

Bash allows you to combine multiple nested steps in a single command using process substitution. It's faster, and more reusable.

Linux Process Management: ps, htop, kill, and nice

Linux has a sophisticated toolset to deal with processes in various circumstances from scripting, to monitoring, to control.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA