Post

Rsync Cheatsheet

Use rsync to copy local files to local directories

Dry run first to see what would be copied without making any changes:

1
rsync -avn source/ destination/

Then run without -n to execute:

1
rsync -av source/ destination/

-a = archive mode (recursive, preserves permissions and timestamps). -n = dry run.

Will rsync only copy the different files?

Yes. By default rsync compares modification time + file size. If both match, the file is skipped. If either differs, it gets copied.

For a more thorough comparison, use --checksum — compares MD5 checksums instead of metadata. Slower but more accurate:

1
rsync -av --checksum source/ destination/

Basic Syntax

1
rsync [options] source destination
1
2
- source: Path of the file or directory to copy from.
- destination: Path of the file or directory to copy to.

Common Options

OptionDescription
-aArchive mode; copies recursively and preserves permissions, times, symbolic links, etc.
-vVerbose; shows progress details.
-zCompresses files during transfer.
-hOutputs numbers in a human-readable format.
–progressShows transfer progress of each file.
–deleteDeletes files in the destination that aren’t in the source.
-rRecursive; used for directories.
–exclude=’pattern’Excludes files that match the given pattern.
-essh Uses SSH for secure file transfer.

Examples

  1. Basic Sync (Local)
1
rsync -av source/ destination/
  1. Remote Sync (over SSH)
1
rsync -avz -e ssh user@remote_host:/path/to/source/ /local/destination/
  1. Sync with Progress and Human-readable Size
1
2
rsync -avh --progress source/ destination/
  1. Delete Extraneous Files in Destination
1
2
3
rsync -av --delete source/ destination/

  1. Exclude Files
1
2
rsync -av --exclude='*.log' source/ destination/
  1. Dry Run (Shows what would happen without making changes)
1
2
rsync -av --dry-run source/ destination/
  1. Sync Only Files Newer in Source
1
rsync -au source/ destination/

Advanced Usage

  1. Mirror Directories
1
2
rsync -avz --delete source/ destination/
  1. Copy Only File Structure (No File Content)
1
rsync -av -f"+ */" -f"- *" source/ destination/
  1. Limit Bandwidth Usage
1
rsync -av --bwlimit=1000 source/ destination/

Tips

  • End with a Slash (/): Appending / to the source copies the contents of the directory, not the directory itself.
  • Dry Run: Always use –dry-run to verify before executing destructive options (e.g., –delete).
  • SSH Shortcut: Use -e ssh for encrypted transfers over SSH.

This cheatsheet covers the essentials to get you started with rsync for efficient file transfers and synchronization tasks!

This post is licensed under CC BY 4.0 by the author.