Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

rsync

Copy and synchronize files and folders (locally or over SSH), sending only what changed.

Niveau
RHCSA-examen
Groep
SSH en werken op afstand
Root nodig
Nee
Pakket
rsync

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

rsync compares the source and the target and transfers only the differences. The first copy is a full copy; the next runs take seconds. It can keep permissions, owners, times, links, ACLs and SELinux contexts, remove files that are gone in the source, limit the bandwidth and resume interrupted transfers.

Remote paths use user@host:path, like scp; rsync uses SSH by default.

The slash rule: rsync -a src/ dst/ copies the content of src into dst. rsync -a src dst/ copies the folder itself, so you get dst/src/.

Zo schrijf je het

rsync [OPTION...] SRC... [DEST]
rsync [OPTION...] SRC... [USER@]HOST:DEST
rsync [OPTION...] [USER@]HOST:SRC... [DEST]

Opties 102

Meest gebruikt

Most used

-a, --archive
Archive mode: recursive and keep links, permissions, times, group, owner, devices (-rlptgoD).
-v, --verbose
Show the files that are transferred.
-z, --compress
Compress data during the transfer.
-n, --dry-run
Show what would happen, change nothing.
-P
Same as --partial --progress: show progress and keep half-done files.
--delete
Delete files in the target that do not exist in the source.
-e, --rsh=command
The remote shell, like -e "ssh -p 2222 -i key".
-h, --human-readable
Readable numbers (K, M, G).
--progress
Show the progress of each file.
--stats
Print statistics at the end.
-i, --itemize-changes
Show a short code for what changes for each file.
-q, --quiet
Show only errors.

What to copy

-r, --recursive
Go into folders.
-d, --dirs
Copy folders without their content.
-R, --relative
Keep the full source path in the target.
--files-from=file
Copy only the names in this file.
--exclude=pattern
Leave out files that match.
--exclude-from=file
Read exclude patterns from a file.
--include=pattern
Do not exclude files that match.
--include-from=file
Read include patterns from a file.
-f, --filter=rule
A filter rule (advanced include/exclude).
-F
Read filter rules from .rsync-filter files.
-C, --cvs-exclude
Leave out files that version control tools ignore.
-x, --one-file-system
Do not cross into other file systems.
--existing
Update only files that already exist in the target.
--ignore-existing
Skip files that already exist in the target.
--max-size=size, --min-size=size
Skip files bigger / smaller than SIZE.
-m, --prune-empty-dirs
Do not create empty folders in the target.
-0, --from0
Names in --files-from are NUL separated.

What to keep

-p, --perms
Keep permissions.
-o, --owner
Keep the owner (root only).
-g, --group
Keep the group.
-t, --times
Keep modification times.
-U, --atimes
Keep access times.
-N, --crtimes
Keep creation times (where supported).
-O, --omit-dir-times
Do not keep the times of folders.
-A, --acls
Keep ACLs (implies -p).
-X, --xattrs
Keep extended attributes (SELinux contexts are kept with -X).
-E, --executability
Keep the execute bit only.
--chmod=mode
Change the permissions of transferred files.
--chown=user:group
Set owner and group of transferred files.
--usermap=map, --groupmap=map
Map user and group names.
--numeric-ids
Keep user and group numbers, do not map by name.
-D
Same as --devices --specials.
--devices, --specials
Copy device files / special files (pipes, sockets).
--copy-devices, --write-devices
Copy the content of devices / write into devices.
-S, --sparse
Keep sparse files sparse.
--preallocate
Reserve the space before writing.
--super, --fake-super
Act as root on the receiver / store privileged attributes as xattrs.

Delete and update

--delete-before, --delete-during (--del), --delete-delay, --delete-after
When to delete extra files in the target.
--delete-excluded
Also delete excluded files in the target.
--max-delete=n
Do not delete more than N files (safety net).
--ignore-errors
Delete even when there are I/O errors.
--force
Delete non-empty folders when they are replaced by a file.
--remove-source-files
Delete the source files after a successful transfer (move).
-u, --update
Skip files that are newer in the target.
-b, --backup
Make backups of files that are replaced or deleted.
--backup-dir=dir
Put the backups in this folder.
--suffix=suffix
The backup ending (default ~).
--inplace
Write updates directly into the target file.
--append, --append-verify
Add data to the end of shorter files (and check them).

Compare

-c, --checksum
Compare by checksum, not by size and time (slower, exact).
--size-only
Compare only the size.
-I, --ignore-times
Do not skip files with the same size and time.
-@, --modify-window=n
Times within N seconds count as the same.
-W, --whole-file
Send whole files, no delta (faster on fast networks).
--checksum-choice=algo
The checksum algorithm.
--compare-dest=dir, --copy-dest=dir
Compare with (or copy from) another folder too.
-y, --fuzzy
Use a similar file in the target as a base.

Transfer

--partial
Keep half-transferred files to resume later.
--partial-dir=dir
Keep half-done files in this folder.
--delay-updates
Put all updated files in place at the end.
-T, --temp-dir=dir
Folder for temporary files.
--bwlimit=rate
Limit the bandwidth, like 10M.
--compress-choice=algo, --compress-level=n
Choose the compression and its level.
--skip-compress=list
Do not compress these file endings.
--timeout=sec, --contimeout=sec
I/O and connect timeouts.
--stop-after=mins, --stop-at=time
Stop after some time / at a time.
--rsync-path=program
The rsync program on the remote side (like "sudo rsync").
-M, --remote-option=opt
Send an option only to the remote side.
-s, --secluded-args
Send file names safely to the remote side.
--fsync
Sync each file to disk.
--log-file=file, --log-file-format=fmt
Write a log file.
--out-format=fmt
Format of the transfer lines.
--info=flags, --debug=flags
Fine control of messages.
--list-only
List the files instead of copying.
--port=port, --address=addr, --password-file=file
For rsync daemon (rsync://) connections.
-4, --ipv4 / -6, --ipv6
Use only IPv4 / IPv6.
--iconv=spec
Convert file name character sets.
--write-batch=file, --read-batch=file
Save a transfer to a file / apply it elsewhere.
-V, --version
Show the version.
--help
Show help.

Voorbeelden 14

$ als gewone gebruiker# als root (of met sudo)

  1. 1Sync a folder to a server

    rsync -av ~/site/ student@server2:/srv/site/

    The slash after site/ copies the content. Run it again: only changes are sent.

  2. 2Dry run first, then the real run

    rsync -avn --delete /var/www/html/ /backup/html/
    rsync -av --delete /var/www/html/ /backup/html/

    Read the list of "deleting" lines before you run without -n.

  3. 3Mirror with deletion

    rsync -a --delete /etc/ /backup/etc-mirror/

    The target becomes an exact copy; files removed in /etc are removed in the backup.

  4. 4Use another SSH port and key

    rsync -avz -e "ssh -p 2222 -i ~/.ssh/backup_key" /data/ backup@nas:/backups/data/

    -e passes options to ssh.

  5. 5Keep SELinux contexts and ACLs

    rsync -aAX /var/www/ server2:/var/www/

    -A ACLs, -X extended attributes (SELinux labels). Needed for a web server migration.

  6. 6Show progress for big files

    rsync -avP rhel-10.iso server2:/srv/iso/

    If the link drops, run the same command again: it resumes.

  7. 7Leave out files

    rsync -av --exclude='*.log' --exclude='.git/' app/ server2:/srv/app/

    Do not ship logs and git history to production.

  8. 8Daily snapshot backups that use little space

    rsync -a --delete --link-dest=/backup/2026-10-24 /home/ /backup/2026-10-25/

    Unchanged files are hard links to yesterday's copy: each day looks full but uses only the changes.

  9. 9Limit the bandwidth

    rsync -av --bwlimit=5M /srv/data/ dr-site:/srv/data/

    About 5 MB/s, so the office network stays usable.

  10. 10Pull files from a server

    rsync -av server2:/var/log/httpd/ ./server2-httpd-logs/

    The remote side can be the source too.

  11. 11Use sudo on the remote side to read root files

    rsync -av --rsync-path="sudo rsync" admin@server2:/etc/ ./server2-etc/

    The remote user needs a sudo rule for rsync.

  12. 12Move files (delete the source after copying)

    rsync -av --remove-source-files /var/spool/export/ archive01:/archive/export/

    Good for files that must leave a server once they are safe elsewhere.

  13. 13Compare two folders by checksum

    rsync -avnc /srv/release/ server2:/srv/release/

    Lists files whose content is different, even if size and time are equal.

  14. 14Safety net for deletions

    rsync -a --delete --max-delete=50 /data/ /backup/data/

    If more than 50 files would be deleted (for example the source is empty by mistake), rsync stops.

Let op

  • The trailing slash on the source changes the result. Check with -n first.
  • --delete with the wrong source (an empty or unmounted folder) can wipe the target. Use -n and --max-delete.
  • Normal users cannot keep owners on the target; run as root (or with --rsync-path="sudo rsync") for full system copies.

Tips om te onthouden

  • rsync -av src/ dst/ = sync content. -n = test, --delete = mirror, -z = compress, -P = progress/resume, -AX = ACLs and SELinux.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man rsync