Linux Terminal Command: rsync

The rsync command is an essential tool in Network Utilities. In this tutorial, we will explore what rsync does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.


Concept & Explanation

The rsync command synchronizes files and directories across hosts. It is highly efficient because it only copies the differences (deltas) between source and target files.


Common Options & Syntax

rsync [options] [arguments]

Here are the most common flags used with rsync:


1. Interactive Example (Simple)

Here is how most people run the command:

# Example
rsync -av ./source/ ./destination/

What it does: Copies files in archive mode (-a preserves symlinks, permissions, times) and shows file details (-v).


2. Power-User Example (Advanced)

For scripting and advanced diagnostics, use this configuration:

# Advanced
rsync -avz --delete --exclude='.git' -e 'ssh -p 2222' ./project/ user@host.com:~/backup/

What it does: Syncs directories, compresses data (-z), deletes target files that no longer exist in the source (--delete), excludes .git, and connects over a custom SSH port.


⚙️ Warning & Common Pitfalls

[!WARNING] A trailing slash on the source directory path matters: ./project/ copies the contents of the folder, while ./project copies the folder itself into the destination.


Here are some related posts on cli_tty1 you might want to check out: