Post

Rsync Cheatsheet

If you have an ssh access to a remote server. Deploying websites with rsync is a great option for simple sites and solo projects.

Here’s a concise rsync cheatsheet for quick reference:

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.