Rsync Command Cheatsheet

Linux logo

rsync is a command-line tool for efficiently syncing files and directories, whether between two local paths or across to a remote machine. It only transfers what’s changed, which makes it ideal for backups and for keeping directories in step. This cheatsheet collects the commands you’ll use most, with a note on what the important flags do.

Most of the examples below use the same four flags, -avzP, so it’s worth knowing them once: -a is archive mode, which preserves permissions, timestamps, and ownership, -v is verbose, -z compresses data during transfer, and -P shows progress and lets an interrupted transfer resume.

Copy from Local to Remote

rsync -avzP /source/ user@remote:/destination/

Replace /source/ with your local directory and user@remote:/destination/ with the target server and path. One thing to watch is the trailing slash on the source: with it, rsync copies the contents of the directory, and without it, it copies the directory itself into the destination.

Copy from Remote to Local

Just swap the order to pull files down from a remote server to your machine:

rsync -avzP user@remote:/source/ /destination/

Exclude Files and Directories

Use --exclude to skip files or folders you don’t want to transfer, and add more --exclude flags for each additional pattern:

rsync -avzP --exclude=folder/ /source/ user@remote:/destination/

Mirror a Directory (Delete Extras)

By default rsync only adds and updates files, it never removes anything. Add --delete to make the destination an exact mirror of the source, removing anything on the far end that no longer exists locally:

rsync -avzP --delete /source/ user@remote:/destination/

Be careful with this one, since a wrong path with --delete can wipe files you meant to keep. It pairs well with the dry run below.

Use a Specific SSH Key or Port

If the remote server uses a non-standard SSH key or port, pass the full SSH command with -e:

rsync -avzP -e "ssh -i /path/to/private/key -p 22" /source/ user@remote:/destination/

Preview with a Dry Run

Add --dry-run to see exactly what rsync would do without changing anything. This is the safest habit to get into, especially before any sync that uses --delete:

rsync -avzP --dry-run /source/ user@remote:/destination/

Once the dry run shows what you expect, drop the flag and run it for real. Between these commands you’ve got everything you need for day-to-day syncing, backups, and mirroring.

Related guides


Comments

2 responses to “Rsync Command Cheatsheet”

  1. Howdy! This post couldn’t be written any better!
    Reading through this article reminds me of my previous roommate!
    He continually kept preaching about this. I most certainly will
    send this article to him. Pretty sure he’s going to have a good read.
    Thank you for sharing!

    1. Thanks Jose! I’m glad you found it useful, Rsync is an awesome tool and I’m sure we will all be using it for many years to come!

Leave a Reply

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