Chapter 40: Bash File Sync (rsync)

Bash File Sync (rsync) day! ☕

This is the real upgrade after we learned cp, mv, and scp. Many people call rsync the king of file copying/syncing in Linux/Bash world — especially in 2026 when everyone has cloud servers, backups, websites, photos, code repos, and slow internet in Hyderabad sometimes.

rsync = remote sync It’s not just “copy” — it’s smart synchronization. It compares source and destination, then only transfers what’s different (changed, new, or missing) — that’s why it’s super fast for backups, website deploys, mirroring folders, or moving huge data over SSH.

Key superpowers:

  • Only sends differences (delta transfer) — even inside big files
  • Preserves permissions, timestamps, owners, symlinks
  • Compresses during transfer (saves bandwidth)
  • Deletes extra files on destination (true mirror)
  • Dry-run (preview without changing anything — lifesaver!)
  • Works locally or remote (over SSH by default)

Think of it as: cp = photocopy everything every time scp = secure photocopy everything every time rsync = smart assistant who checks “what changed?” and only updates those parts — like Google Drive sync but in terminal.

Basic Syntax (Memorize This!)

Bash

Note the trailing / after source — very important! It means “copy the contents of source into destination”, not the folder itself.

Without / on source → copies the folder as a subfolder.

1. Most Important Combo Everyone Uses: -avz (or -aP)

Bash

What each letter means:

  • -a → archive mode = -rlptgoD (recursive + links + permissions + timestamps + group + owner + devices/specials) → Almost perfect copy — preserves everything important
  • -v → verbose = shows what files are transferred
  • -z → compress during transfer = saves bandwidth (great on Jio/Airtel)

Real example — backup your Documents:

Bash

→ Only new/changed files go to backup

Add -P (progress + partial) for big transfers:

Bash
  • Shows progress bar
  • Resumes if interrupted (Ctrl+C then run same command again)

2. Remote Sync Over SSH (Most Powerful Use)

rsync uses SSH automatically when you give remote path like scp.

Local → Remote (upload website):

Bash

Remote → Local (download logs):

Bash

Mirror exactly (delete extras on destination):

Bash

→ If you deleted a file in source → it deletes on destination too (careful!)

3. Dry Run – ALWAYS Do This First! (–dry-run or -n)

Preview what will happen — no changes made.

Bash

→ Shows “would transfer these files”, “would delete those” — super safe before real run.

4. Other Very Useful Options Table

Option What it does Example Use Case
–dry-run / -n Simulate only — no actual changes Test before dangerous sync
–delete Delete files on dest that are gone from source True mirror / clean backup
–exclude=’pattern’ Skip files/folders matching pattern –exclude=’*.tmp’ –exclude=’node_modules/’
–include=’pattern’ Force include certain files (overrides exclude) Selective sync
–progress / -P Show progress bar + allow resume Big files over slow net
–human-readable / -h Sizes in KB/MB/GB instead of bytes Easier to read
–stats Summary stats at end How many files, bytes transferred
–bwlimit=KB/s Limit bandwidth (e.g. 500) Don’t kill internet for family
-e “ssh -p 2222” Custom SSH options (port, key, etc.) Non-standard port

Super common full command for website deploy:

Bash

5. Practice Session Right Now (Safe!)

Bash

See how smart it is? Only transfers changes!

6. rsync vs scp vs cp (Quick Teacher Comparison)

Feature cp scp rsync
Speed for repeat sync Full copy always Full copy always Only differences (fastest)
Resume interrupted No No Yes (-P)
Preserve everything With -p/-a With -p Best with -a
Delete extras No No Yes (–delete)
Compress transfer No No Yes (-z)
Remote support Local only Yes (SSH) Yes (SSH by default)
Dry-run / preview No No Yes (–dry-run)
Best for Local quick copy One-time secure copy Backups, deploys, mirrors

In 2026 — use rsync for almost everything except tiny one-time copies.

7. Teacher Warnings

  • Trailing / matters — practice it!
  • –delete is dangerous — always –dry-run first!
  • Never rsync / or important system folders without extreme care
  • For huge datasets → add –bwlimit or run at night
  • SSH keys make it passwordless & script-friendly

Got the power now? rsync is your smart backup/deploy/sync friend — once you start using -avz –delete –dry-run, you’ll never go back to plain cp/scp for serious work.

Any part confusing? Want next: “Teacher, show rsync cron job for daily backup” or “exclude patterns deep dive” or “rsync daemon mode” or back to other commands?

Tell me — teacher is ready in Hyderabad! Keep syncing smartly! 🐧🔄📂 😄

You may also like...

Leave a Reply

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