|

Linux CLI 40 ๐Ÿง rsync command

rsync -av /home/kr/cli /home/kr/clibkp

rsync -avz user@192.168.1.100:/home/kr/cli /home/kr/clibkp

rsync -av --delete /home/kr/cli user@192.168.1.100:/home/kr/cli

rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

ssh-copy-id user@remote_host

rsync -avz --delete /source/dir/ user@remote_host:/destination/dir/

rsync is the workhorse of file synchronization on Linux. It can copy files locally, transfer them across the network over SSH, and โ€” most importantly โ€” synchronize two locations so they match. It only transfers what has changed, which makes it dramatically faster than cp or scp for repeated operations.

Key point: rsync is incremental. The first run copies everything; later runs copy only the differences. Add --delete and it becomes a true mirror โ€” the destination is made to look exactly like the source.


a – rsync command

rsync is a powerful command used to transfer files over a network. It can copy files between local and remote systems and synchronize directories. It supports various options to control the transfer process.

Common options:

OptionPurpose
-aArchive mode โ€” preserves permissions, timestamps, symlinks, ownership
-vVerbose mode
-zCompress data during transfer
-PShow progress and support pausing/resuming
-eSpecify an alternative remote shell (-e ssh)
-rRecursive (for directories)
-nDry run โ€” show what would happen without doing it
--deleteDelete files in destination that don’t exist in source
--excludeSkip matching files
--progressShow per-file progress
-hHuman-readable numbers

Syntax:

rsync [options] [src] [user@]host:target
rsync [options] [user@]host:src [target]

The colon is what makes a path remote. host:/path is remote; /path is local.

Examples:

# Local copy
$ rsync -av /home/kr/cli /home/kr/clibkp
sending incremental file list
cli/
cli/file1.txt
cli/file2.txt
cli/subdir/
cli/subdir/file3.txt

sent 1,234 bytes  received 567 bytes  3,602.00 bytes/sec
total size is 10,240  speedup is 5.68

# Remote โ†’ local
$ rsync -avz user@192.168.1.100:/home/kr/cli /home/kr/clibkp
receiving incremental file list
cli/
cli/file1.txt
...

# Local โ†’ remote with compression and progress
$ rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli
sending incremental file list
cli/
cli/file1.txt
      1,024 100%    1.02MB/s    0:00:00 (xfr#1, to-chk=3/5)
...

# Sync with deletion of removed files
$ rsync -av --delete /home/kr/cli user@192.168.1.100:/home/kr/cli

# Dry run first (very important with --delete!)
$ rsync -avn --delete /home/kr/cli user@192.168.1.100:/home/kr/cli

# Exclude patterns
$ rsync -av --exclude='*.log' --exclude='.git' /home/kr/cli /backup/

# Specify SSH explicitly
$ rsync -avz -e ssh /home/kr/cli user@192.168.1.100:/home/kr/cli

# Use a custom SSH port
$ rsync -avz -e 'ssh -p 2222' /home/kr/cli user@192.168.1.100:/home/kr/cli

# Human-readable output
$ rsync -avh /home/kr/cli /backup/

# Show per-file progress
$ rsync -av --progress /home/kr/cli /backup/

How the trailing slash changes everything:

# With trailing slash on source โ€” copies CONTENTS into target
$ rsync -av /home/kr/cli/ /home/kr/clibkp/
# Result: /home/kr/clibkp/file1.txt, /home/kr/clibkp/file2.txt

# Without trailing slash โ€” copies the DIRECTORY itself into target
$ rsync -av /home/kr/cli /home/kr/clibkp/
# Result: /home/kr/clibkp/cli/file1.txt, /home/kr/clibkp/cli/file2.txt

This is the single most common source of confusion with rsync. A trailing slash on the source means “copy the contents.” No trailing slash means “copy the directory.”

How rsync’s delta algorithm works:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           First rsync run                    โ”‚
โ”‚                                              โ”‚
โ”‚  Source:      file1, file2, file3            โ”‚
โ”‚  Destination: (empty)                        โ”‚
โ”‚                                              โ”‚
โ”‚  โ†’ copies all three files                    โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           Second rsync run                   โ”‚
โ”‚                                              โ”‚
โ”‚  Source:      file1, file2', file3           โ”‚
โ”‚  Destination: file1, file2, file3            โ”‚
โ”‚                                              โ”‚
โ”‚  โ†’ file2 changed, only file2' is transferred โ”‚
โ”‚  โ†’ files 1 and 3 are skipped (same size/mtime)โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

rsync compares size and modification time by default. If they match, it assumes the file is unchanged and skips it. This is what makes it fast.


b – rsync examples

Here are the most common real-world uses of rsync, from simple local copies to full remote synchronization.

1. Local copy:

$ rsync -av /home/kr/cli /home/kr/clibkp

Copies the cli directory to clibkp. Preserves permissions, timestamps, and symlinks. On later runs, only changed files are copied.

2. Copy from remote to local:

$ rsync -avz user@192.168.1.100:/home/kr/cli /home/kr/clibkp

Copies everything from the remote machine to the local one. The -z compresses data in transit โ€” good for slow links.

3. Synchronize directories and delete extras:

$ rsync -av --delete /home/kr/cli user@192.168.1.100:/home/kr/cli

Synchronizes the two directories and deletes files in the destination that don’t exist in the source. This makes the destination an exact mirror.

โš ๏ธ Warning: --delete is destructive. Always run with -n (dry run) first to see what would be deleted.

4. Pause and resume:

$ rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli

Press Ctrl+C to pause; run the same command to resume. The -P flag enables --partial and --progress, so partially transferred files are kept and resumed instead of restarted.

5. SSH key-based authentication:

If you frequently use rsync between two machines, set up SSH keys so you don’t type a password every time.

# Generate a key pair
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kr/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kr/.ssh/id_rsa
Your public key has been saved in /home/kr/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:abc123def456... your_email@example.com

# Copy the public key to the remote machine
$ ssh-copy-id user@remote_host
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
...
Number of key(s) added: 1

# Now rsync runs without asking for a password
$ rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli

6. Full sync with key auth:

$ rsync -avz --delete /source/dir/ user@remote_host:/destination/dir/

The classic backup/mirror command. Compressed, incremental, deletes extras on the destination, and runs without a password thanks to the SSH key.

More examples:

# Dry run (safe preview)
$ rsync -avn --delete /source/ user@host:/dest/

# Exclude patterns
$ rsync -av --exclude='*.tmp' --exclude='node_modules' /project/ /backup/

# Exclude via file
$ rsync -av --exclude-from=.rsyncignore /project/ /backup/

# Bandwidth limit (KB/s)
$ rsync -avz --bwlimit=1000 /source/ user@host:/dest/

# Preserve hard links
$ rsync -avH /source/ /dest/

# Preserve ACLs and extended attributes
$ rsync -avAX /source/ /dest/

# Delete excluded files on destination too
$ rsync -av --delete --delete-excluded --exclude='*.log' /source/ /dest/

# Sync into an existing directory without renaming
$ rsync -av /source/. /dest/

# Show what would be transferred without -v noise
$ rsync -an --stats /source/ /dest/

# Back up with a timestamped directory
$ rsync -av /source/ /backup/$(date +%F)/

# Use rsync as a faster cp
$ rsync -av /src/ /dst/

Complete Example Session

# ============================================
# PART 1: LOCAL COPY
# ============================================

$ rsync -av /home/kr/cli /home/kr/clibkp
sending incremental file list
created directory /home/kr/clibkp
cli/
cli/file1.txt
cli/file2.txt
cli/subdir/
cli/subdir/file3.txt

sent 1,234 bytes  received 567 bytes  3,602.00 bytes/sec
total size is 10,240  speedup is 5.68

# Run again โ€” only changed files transfer
$ rsync -av /home/kr/cli /home/kr/clibkp
sending incremental file list

sent 123 bytes  received 17 bytes  280.00 bytes/sec
total size is 10,240  speedup is 73.14
# โœ… Nothing to copy โ€” fast!

# ============================================
# PART 2: REMOTE COPY (REMOTE โ†’ LOCAL)
# ============================================

$ rsync -avz user@192.168.1.100:/home/kr/cli /home/kr/clibkp
receiving incremental file list
cli/
cli/file1.txt
cli/file2.txt
cli/subdir/file3.txt

sent 123 bytes  received 1,234 bytes  904.67 bytes/sec
total size is 10,240  speedup is 7.54

# ============================================
# PART 3: SYNC WITH --DELETE
# ============================================

# Dry run first
$ rsync -avn --delete /home/kr/cli user@192.168.1.100:/home/kr/cli
sending incremental file list
deleting oldfile.txt
cli/
cli/file4.txt

# Then for real
$ rsync -av --delete /home/kr/cli user@192.168.1.100:/home/kr/cli
sending incremental file list
deleting oldfile.txt
cli/file4.txt

sent 1,234 bytes  received 567 bytes  3,602.00 bytes/sec
total size is 12,288  speedup is 6.82

# ============================================
# PART 4: PAUSE AND RESUME
# ============================================

$ rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli
sending incremental file list
cli/
cli/bigfile.iso
  524,288,000  50%   10.20MB/s    0:00:50 (xfr#1, to-chk=2/5)
^C
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20)

# Run the same command to resume
$ rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli
sending incremental file list
cli/bigfile.iso
  524,288,000  50%   10.20MB/s    0:00:50 (xfr#1, to-chk=2/5)
# โœ… Resumes from where it stopped

# ============================================
# PART 5: SSH KEY AUTHENTICATION
# ============================================

# Generate a key pair
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kr/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kr/.ssh/id_rsa
Your public key has been saved in /home/kr/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:abc123def456... your_email@example.com

# Copy the public key to the remote
$ ssh-copy-id user@remote_host
Number of key(s) added: 1

# Test passwordless login
$ ssh user@remote_host
# โœ… no password prompt

# Now rsync without password
$ rsync -avzP /home/kr/cli user@192.168.1.100:/home/kr/cli
# โœ… no password prompt

# ============================================
# PART 6: FULL SYNC COMMAND
# ============================================

$ rsync -avz --delete /source/dir/ user@remote_host:/destination/dir/
sending incremental file list
deleting oldfile.txt
file1.txt
file2.txt
...

sent 1,234 bytes  received 567 bytes  3,602.00 bytes/sec
total size is 10,240  speedup is 5.68

# ============================================
# PART 7: EXCLUDE PATTERNS
# ============================================

$ rsync -av --exclude='*.log' --exclude='node_modules' --exclude='.git' \
    /home/kr/project/ /backup/project/
sending incremental file list
project/
project/src/
project/src/main.c
project/README.md
# โœ… .log, node_modules, .git skipped

# ============================================
# PART 8: BANDWIDTH LIMIT
# ============================================

$ rsync -avz --bwlimit=1000 /home/kr/bigdata/ user@host:/backup/
# Limited to ~1 MB/s

# ============================================
# PART 9: STATS
# ============================================

$ rsync -an --stats /source/ /dest/
Number of files: 123
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0
Total file size: 10,240 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 0
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 123
Total bytes received: 17
# โœ… Nothing to do

Quick Reference

rsync โ€” Core Options

OptionPurpose
-aArchive mode (perms, times, links)
-vVerbose
-zCompress in transit
-PProgress + partial (resume)
-rRecursive
-nDry run
-hHuman-readable
--deleteDelete extras in destination
--exclude=PATSkip matching files
--exclude-from=FILERead exclude patterns from file
--progressShow per-file progress
--statsShow summary statistics
--bwlimit=KBPSLimit bandwidth
-e sshUse SSH explicitly
-HPreserve hard links
-APreserve ACLs
-XPreserve extended attributes

rsync โ€” Common Recipes

CommandPurpose
rsync -av SRC DSTLocal copy
rsync -avz user@host:SRC DSTRemote โ†’ local
rsync -avz SRC user@host:DSTLocal โ†’ remote
rsync -av --delete SRC DSTMirror (delete extras)
rsync -avn --delete SRC DSTDry-run mirror
rsync -avzP SRC user@host:DSTResumable transfer
rsync -av -e 'ssh -p 2222' SRC DSTCustom SSH port
rsync -av --exclude='*.log' SRC DSTExclude patterns
rsync -av --bwlimit=1000 SRC DSTLimit speed
rsync -av SRC/ DST/Copy contents (trailing slash)
rsync -av SRC DST/Copy directory itself

SSH Keys

CommandPurpose
ssh-keygen -t rsa -b 4096 -C "email"Generate RSA-4096 key
ssh-keygen -t ed25519 -C "email"Generate Ed25519 key (modern)
ssh-copy-id user@hostCopy public key to remote
ssh user@hostTest passwordless login

Best Practices

โœ… Do This:

# Always dry-run with --delete
rsync -avn --delete SRC DST          # โœ…

# Use -a to preserve metadata
rsync -av SRC DST                    # โœ…

# Use -z over slow links
rsync -avz SRC user@host:DST         # โœ…

# Use -P for large transfers (resumable)
rsync -avzP SRC user@host:DST        # โœ…

# Set up SSH keys for frequent syncs
ssh-keygen && ssh-copy-id user@host  # โœ…

# Trailing slash = contents
rsync -av SRC/ DST/                  # โœ… copies contents
rsync -av SRC DST/                   # โœ… copies directory

# Exclude junk
rsync -av --exclude='.git' SRC DST   # โœ…

# Use --bwlimit to avoid saturating links
rsync -avz --bwlimit=1000 SRC DST    # โœ…

# Verify with --stats on dry run
rsync -an --stats SRC DST            # โœ…

โŒ Don’t Do This:

# Don't use --delete without a dry run first
rsync -av --delete SRC DST           # โŒ dangerous

# Don't confuse trailing slashes
rsync -av SRC DST                    # โŒ creates DST/SRC
rsync -av SRC/ DST/                  # โœ… contents only

# Don't use rsync for one-time copies (use cp)
rsync -av SRC DST                    # โš ๏ธ  overkill for a one-off

# Don't forget -z on slow networks
rsync -av SRC user@host:DST          # โŒ slower

# Don't sync without key auth for automation
rsync -av SRC user@host:DST          # โŒ password prompts

# Don't sync a live database without quiescing
rsync -av /var/lib/mysql/ /backup/   # โŒ inconsistent

# Don't run --delete in the wrong direction
rsync -av --delete EMPTY/ FULL/      # โŒ wipes FULL

Common Pitfalls

PitfallProblemSolution
Trailing slash confusionFiles land in wrong placeRemember: slash = contents
--delete deletes too muchData lossDry run first with -n
No -aPermissions/times not preservedUse -av
Slow over networkNo compressionAdd -z
Password promptsNo key authSet up SSH keys
Partial transfer lostNo -PUse -avzP
Files skipped unexpectedlySize+mtime matchUse -c (checksum)
Wrong direction with --deleteWipes source of truthDouble-check SRC/DST
Symlinks followedUnexpected copiesUse -a (preserves links)
.git copiedHuge unnecessary transferExclude it

Real-World Examples

1. Back Up Your Home Directory

$ rsync -av --delete /home/kr/ /backup/home/
sending incremental file list
...
sent 1,234,567 bytes  received 8,901 bytes  2,486,936.00 bytes/sec
total size is 42,000,000,000  speedup is 33,800.00

2. Mirror a Website to a Remote Server

$ rsync -avz --delete /var/www/html/ user@192.168.1.100:/var/www/html/

3. Sync a Project to a Server for Testing

$ rsync -avzP --exclude='.git' --exclude='node_modules' \
    /home/kr/project/ user@test-server:/srv/project/

4. Download a Large Directory from a Server

$ rsync -avzP user@192.168.1.100:/data/ /local/data/

5. Timestamped Backups

$ rsync -av /home/kr/documents/ /backup/documents-$(date +%F)/

6. Resume an Interrupted Transfer

# Ctrl+C to stop
$ rsync -avzP /data/ user@host:/backup/
^C

# Run the same command to resume
$ rsync -avzP /data/ user@host:/backup/

7. Bandwidth-Limited Sync Over a Slow Link

$ rsync -avz --bwlimit=500 /home/kr/archive/ user@host:/backup/
# Limited to ~500 KB/s

8. Set Up Passwordless rsync

$ ssh-keygen -t ed25519 -C "backup@olympos"
$ ssh-copy-id user@192.168.1.100
$ rsync -avzP /home/kr/ user@192.168.1.100:/backup/
# โœ… no password

9. Exclude Files via a Pattern File

$ cat ~/.rsync-exclude
.git/
node_modules/
*.log
*.tmp

$ rsync -av --exclude-from=~/.rsync-exclude /project/ /backup/

10. Sync Only New Files (No Overwrites)

$ rsync -av --ignore-existing /source/ /dest/
# Skips files already present in dest

11. Verify with Checksums Instead of Time

$ rsync -avc /source/ /dest/
# Uses checksums โ€” slower but more accurate

12. Delete Only Files Removed from Source

$ rsync -av --delete --ignore-existing /source/ /dest/
# Only deletes files no longer in source, doesn't overwrite existing

13. Show Only the Summary

$ rsync -a --stats /source/ /dest/

14. Sync with a Custom SSH Key

$ rsync -avz -e 'ssh -i ~/.ssh/backup_key' /source/ user@host:/dest/

15. Pull Backup from a Server

$ rsync -avz --delete user@server:/var/www/ /backup/www/

Visual: How rsync Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              First rsync run                 โ”‚
โ”‚                                              โ”‚
โ”‚  Source                 Destination          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚  โ”‚ file1    โ”‚           โ”‚          โ”‚         โ”‚
โ”‚  โ”‚ file2    โ”‚   โ”€โ”€โ”€โ”€โ–บ   โ”‚          โ”‚         โ”‚
โ”‚  โ”‚ file3    โ”‚           โ”‚          โ”‚         โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ”‚                                              โ”‚
โ”‚  All files copied                            โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚             Second rsync run                 โ”‚
โ”‚                                              โ”‚
โ”‚  Source                 Destination          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚  โ”‚ file1    โ”‚   skip    โ”‚ file1    โ”‚         โ”‚
โ”‚  โ”‚ file2'   โ”‚   โ”€โ”€โ”€โ”€โ–บ   โ”‚ file2    โ”‚         โ”‚
โ”‚  โ”‚ file3    โ”‚   skip    โ”‚ file3    โ”‚         โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ”‚                                              โ”‚
โ”‚  Only file2' transferred (file2 changed)     โ”‚
โ”‚  file1 and file3 are skipped                 โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

CommandPurposeExample
rsync -av SRC DSTLocal copyrsync -av /home/kr/cli /home/kr/clibkp
rsync -avz user@host:SRC DSTRemote โ†’ localrsync -avz user@192.168.1.100:/home/kr/cli /home/kr/clibkp
rsync -avz SRC user@host:DSTLocal โ†’ remotersync -avzP /home/kr/cli user@host:/home/kr/cli
rsync -av --delete SRC DSTMirror + delete extrasrsync -av --delete /home/kr/cli user@host:/home/kr/cli
rsync -avzP SRC user@host:DSTResumable transferrsync -avzP /home/kr/cli user@host:/home/kr/cli
rsync -avn SRC DSTDry runrsync -avn --delete SRC DST
rsync -av --exclude=PAT SRC DSTExclude patternsrsync -av --exclude='.git' SRC DST
rsync -avz --bwlimit=N SRC DSTBandwidth limitrsync -avz --bwlimit=1000 SRC DST
ssh-keygen -t rsa -b 4096 -C "email"Generate key pairssh-keygen -t rsa -b 4096 -C "me@x.com"
ssh-copy-id user@hostCopy public keyssh-copy-id user@remote_host

Key takeaways:

  • rsync copies and synchronizes files โ€” local or remote โ€” and only transfers changes
  • -a preserves permissions, timestamps, symlinks, and ownership โ€” always use it for backups
  • -v for verbose, -z for compression, -P for progress and resume
  • --delete makes the destination an exact mirror โ€” always dry-run first with -n
  • Trailing slash on the source matters: SRC/ = contents, SRC = the directory itself
  • The colon (user@host:/path) marks a remote path
  • -P lets you Ctrl+C and resume by running the same command
  • Set up SSH keys (ssh-keygen + ssh-copy-id) for passwordless rsync
  • Use --exclude to skip .git, node_modules, *.log, and other junk
  • Use --bwlimit to avoid saturating a network link
  • For very large transfers, rsync beats scp because it resumes and only sends deltas

Remember: rsync is the most powerful file-copying tool on Linux. It’s faster than cp for repeated syncs because it only transfers what changed. It’s more reliable than scp for large transfers because it can resume. And with --delete, it turns any two directories into an exact mirror โ€” but that power comes with risk, so always dry-run with -n first. Watch your trailing slashes. Set up SSH keys. Exclude the junk. Master rsync, and backups, deployments, and file synchronization all become one command.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!