- Rsync synchronizes by differences, saving time and bandwidth with its delta-transfer algorithm.
- Trailing slashes matter: SOURCE/ copies contents; without a trailing slash, it creates the directory within the destination.
- Safety and reliability: use SSH, keys, -P to resume and --dry-run before --delete.
- Complete flexibility: exclusions, limits, compression, backups, and scheduled tasks with cron.

If you work with Linux and handle files daily, rsync is the Swiss Army knife for synchronizing and transferring data between local directories and remote servers quickly, securely, and efficiently. It not only copies, but also compares and sends only what has changed, saving time and bandwidth.
In this practical guide, you'll learn to master rsync step by step: from its basic syntax and key options to advanced techniques like exclusions, secure deletions, resuming transfers, backups, and cron automation. You'll also see how to use it with SSH, passwordless keys, and size and speed limits.
What is rsync and why is it so fast?
Rsync stands for "remote synchronization." It's an open-source tool for synchronizing directories and files between local or remote locations (over a network). Its key strength is the "delta-transfer" algorithm: it analyzes metadata and content in blocks and transfers only the differences , drastically reducing the amount of data sent.
It is available on virtually all GNU/Linux distributions and Unix -like systems . Its behavior is similar to cp and scp , but with many more fine-grained options: it preserves permissions, resumes cuts, compresses on the fly, excludes patterns, displays progress, and much more.
Basic syntax and key concepts
The general form of the command is: rsync SOURCE DESTINATION . SOURCE and DESTINATION can be local paths or remote endpoints via SSH, for example user@host:/path.
When using a remote host, the syntax is: rsync HOST:REMOTE_PATH LOCAL_PATH (pull) or rsync LOCAL_PATH HOST:REMOTE_PATH (push). In both cases, the source comes first and the destination comes later.
rsync
rsync HOST:ORIGEN_REMOTO DESTINO_LOCAL # PULL
rsync ORIGEN_LOCAL HOST:DESTINO_REMOTO # PUSH
There's a vital nuance: the trailing slash in the source. SOURCE/ (with a slash) means "contents of SOURCE" ; if you omit the slash, rsync will create the SOURCE directory within the destination.
Check and install rsync
First, check if it's available with `rsync --version` ; you'll see the number and protocol. If you don't have it, you can install it using your distribution's installer.
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install rsync
# Red Hat / CentOS / Fedora
sudo yum install rsync # o: sudo dnf install rsync
# macOS (Homebrew)
brew install rsync
If you manage a server from Windows , you can connect via SSH using PuTTY and run the same commands from the remote terminal.
Getting Started: Quick Local Sync
Prepare two test folders and some empty files. This will allow you to see the difference between copying everything and updating only changes, thanks to the rsync algorithm.
cd ~
mkdir dir1 dir2
# Crea 100 ficheros vacíos
bash -c 'touch dir1/file{1..100}'
# Sincroniza de dir1 a dir2 (recursivo)
rsync -r dir1/ dir2
# O en modo "archivo" (recomendado)
rsync -a dir1/ dir2
The -r option copies recursively; -a (archive) encompasses -r and also preserves permissions, owner, group, timestamps, and symbolic links.
Final bar at the origin: the detail that avoids surprises
This behavior is key: dir1/ transfers the content; dir1 copies the entire directory into the destination. Test it safely with a dry run.
# Ensayo (no cambia nada) y verboso
rsync -anv dir1/ dir2 # contenido de dir1 hacia dir2
rsync -anv dir1 dir2 # crea dir2/dir1/...
For delicate operations, get into the habit of adding `-n` or `--dry-run` and checking the output before actually running the command. It's a small habit that saves a lot of trouble.
Remote synchronization with SSH: push and pull
If you have SSH on the remote machine and rsync installed on both sides, sending or retrieving data is as simple as a path with user@host . By default, rsync will use SSH as the "remote shell".
# PUSH: del local al remoto (transferimos el directorio completo)
rsync -a ~/dir1 usuario@servidor:/ruta/destino
# PULL: del remoto al local (traemos contenidos)
rsync -a usuario@servidor:/home/usuario/dir1 /ruta/local
# Especificar el puerto SSH y usar compresión y progreso
rsync -azP -e 'ssh -p 2222' origen/ usuario@servidor:/destino/
The -z (comprehension) and -P (progress + partials) options are a lifesaver on slow networks: you'll see progress bars and you can resume if the connection drops.
Passwordless authentication with SSH keys
To automate synchronization, it's best to use keys. Generate an RSA/ed25519 pair, copy the public key to the server, and use it with rsync to avoid password prompts.
# En el cliente (usuario local)
ssh-keygen -t rsa -b 4096 -C "Acceso rsync" -f ~/.ssh/rsync_key -q -N ""
ssh-copy-id -i ~/.ssh/rsync_key.pub usuario@servidor
# Probar acceso por clave
ssh -i ~/.ssh/rsync_key usuario@servidor
# Usar la clave con rsync (dos formas equivalentes)
rsync -az -e 'ssh -i ~/.ssh/rsync_key' origen/ usuario@servidor:/destino/
rsync -az --rsh="ssh -i ~/.ssh/rsync_key" origen/ usuario@servidor:/destino/
If you do not have root permissions on the destination , you can ignore owner and group with –no-o and –no-g , which avoids attribution errors on multi-user systems.
Essential options that you will use all the time
The most common combinations mix -a (archive), -v (verbose), -z (compress), -P (progress/partials) depending on the case. Note these essentials.
- -a: recursive and preserves permissions, times, owner, group, links and specials.
- -v: more informative output; with -h you will see “human-readable” sizes.
- -z: compress during transfer (avoid if files are already compressed).
- -P: is equivalent to –progress + –partial; ideal for unstable links.
Also very useful: -u (update, doesn't overwrite if the destination is newer), -n (dry-run) and -e for the remote shell (e.g., SSH with port or key).
Progress, compression and resumption without wasting time
To visualize what's happening and avoid starting from scratch after a break, `-azP` is usually the winning formula . You'll see how much is left, and `rsync` will save partial chunks to continue.
rsync -azP origen/ destino/
# Repetirlo cuando no cambie nada da una salida mínima: rsync detecta que todo está al día
If after touching dates with touch or modifying some files you run the command again, only the altered ones will be sent , confirming the efficiency of delta-transfer.
Exclusions and inclusions by pattern
When you don't want to include everything, use `--exclude` and `--include` to refine your selection . You can exclude by name, path, or extension, or load a list from a file.
# Excluir un directorio, un fichero y rutas concretas
rsync -av --exclude 'cache/' --exclude 'secreto.doc' --exclude 'ruta/subdir' origen/ destino/
# Excluir desde archivo (uno por línea)
rsync -av --exclude-from 'lista_excluidos.txt' origen/ destino/
# Solo copiar .jpg en toda la jerarquía (incluye directorios, excluye el resto)
rsync -vrhz --include="*/" --include="*.jpg" --exclude="*" original/ duplicados/
If you go overboard with exclusions, you can always reverse the logic with –include to allow what you really want and block the rest with –exclude "*".
Controlled deletion at destination (–delete and variants)
For a "mirror" synchronization, enable `--delete` and files that no longer exist in the source will be deleted from the destination. Use this with caution and always test with `--dry-run` first.
# Sincronización espejo (borra en destino lo que ya no está en origen)
rsync -av --delete origen/ destino/
Deletion policies: –delete-before (deletes before transferring), –delete-during (during reception; default in modern versions), and –delete-delay (detects missing files and deletes at the end). –delete-after exists, but is usually less efficient except in very specific scenarios.
Size and bandwidth limits
To avoid overloading the network or filtering by size, use `--max-size` and `--min-size` along with `--bwlimit` . These are useful for bulk copies or backups with specific policies.
# Solo archivos <= 100 MB y límite de 5 MB/s
rsync -avzh --max-size='100M' --bwlimit=5120 origen/ destino/
# No transferir nada por debajo de 10 KB
dsync -av --min-size=10k origen/ destino/
When moving a lot of small files, -W/-whole-file forces the entire file to be sent and can speed things up if the delta doesn't compensate for the latency.
Hassle-free backups (–backup and –backup-dir)
If you're worried about overwriting, combine `--backup` with `--backup-dir` to keep previous versions in a backup folder. It's a very handy "safety net."
# Guarda versiones reemplazadas/eliminadas en /var/backups/rsync
rsync -a --delete --backup --backup-dir=/var/backups/rsync /ruta/origen/ /ruta/destino/
This way, any file modified or deleted at the destination will be safe in the indicated directory, making it easy to quickly revert if something doesn't go as planned.
Automate with cron (without prompts or noise)
To run regular synchronizations, add an entry to cron. Use SSH keys, avoid `--progress`, and optionally, dump a log for auditing.
# Cada hora, con clave e ignorando propietario y grupo
0 * * * * rsync -arz --no-o --no-g --delete --rsh="ssh -i /home/u/.ssh/rsync_key" /home/u/backup/ u@servidor:"/home/u/backup" >> /var/log/rsync.log 2>&1
If you're syncing in the opposite direction, reverse the SOURCE and DESTINATION. Logging with `--log-file` or redirection will help you review what was transferred and when.
Advanced tricks and real-life scenarios
In addition to the classic ones, rsync has lesser-known but very useful flags: -c (checksum, ignores dates/sizes and compares by hash), –size-only (size only), -I/–ignore-times (copies everything), –remove-source-files (moves instead of copying, does not delete directories).
# Solo actualizar si cambia el hash (más preciso, más CPU)
rsync -avuc origen/ destino/
# Mover ficheros (borra en origen los que se copien bien)
rsync -av --remove-source-files origen/ destino/
# Preservar enlaces, dueños y especiales (requiere permisos adecuados)
rsync -aLptgoD origen/ destino/
With remote servers, you can synchronize two Linux machines via SSH every hour using cron and keys. If you need near real-time synchronization, check out Lsyncd , a daemon that reacts to filesystem changes and automatically calls rsync. If you prefer a graphical interface, try synchronizing local and network folders with FreeFileSync.
Compact examples to get you out of trouble
Here are some quick recipes to remember. You can easily adapt them to your routes and users .
# Copiar localmente con progreso y tamaños legibles
rsync -avhP /carpeta1/ /carpeta2/
# Sincronizar dos hosts (pull) con progreso
rsync -avP [email protected]:/carpeta1/ /carpeta2/
# Solo archivos modificados (update) a un remoto
rsync -vzh -u posts/*.md blog@host:/ruta/posts/
# Ensayo general (no cambia nada) y listado detallado
rsync -avhni --itemize-changes origen/ destino/
When dealing with large structures, combine exclusions, limits, and progress to have absolute control over what travels and how it does so.
Mastering rsync is a matter of practice: experiment with `--dry-run`, use `-a` as a base, add `-z`/`-P` for network operation, and use `--delete` wisely . With SSH keys and cron, you'll have automatic, secure, and efficient synchronizations both locally and between servers.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.