Updated: 11 October 2026 · Applies to: rsync 3.2.7 (Ubuntu 24.04), 3.4.1 (Ubuntu 26.04) and 3.5.0 (Debian 13, AlmaLinux 10)
To copy files with rsync, run rsync -av SOURCE DESTINATION. For example rsync -av site/ /backup/site/ copies the contents of the site folder to /backup/site/, keeping permissions, owners and timestamps. To copy to another server over SSH, put user@server: in front of the remote path: rsync -avz site/ user@server:/var/www/site/. Run the same command again later and rsync copies only what changed.
rsync -av file.txt /backup/ # one file rsync -av site/ /backup/site/ # a folder's contents, on the same machine rsync -avz site/ user@server:/var/www/site/ # to a server over SSH rsync -avz user@server:/var/www/site/ site/ # from a server rsync -avz -e "ssh -p 2222" site/ user@server:/var/www/site/ # SSH on another port
Install rsync
Many minimal server images do not include rsync. For copies between two machines it must be installed on both.
sudo apt install rsync # Ubuntu, Debian sudo dnf install rsync # AlmaLinux, Rocky Linux, RHEL, Fedora rsync --version
The options you need
-a(archive): copies folders recursively and keeps symbolic links, permissions and timestamps, plus owner and group when the receiving side runs as root. Use it for almost every copy.-vlists each file;-hprints sizes as K, M and G.-zcompresses data on the way. Useful over the internet, not for local copies.-n(--dry-run) shows what would happen without changing anything.-P(--partial --progress) shows progress and lets an interrupted large file resume.--deleteremoves files from the destination that no longer exist in the source.--exclude=PATTERNskips matching files or folders.-e "ssh -p PORT"sets the SSH command, for example a non-standard port.
Step 1: Copy a single file
$ rsync -av notes.txt /backup/ sending incremental file list created directory /backup notes.txt sent 107 bytes received 65 bytes 114.67 bytes/sec total size is 6 speedup is 0.03
Several files at once: rsync -av notes.txt site/index.php /backup/two/. rsync creates the last folder of the destination if it is missing, but not the folders above it. rsync -av site/ /nonexistent/deep/path/ fails with mkdir "/nonexistent/deep/path" failed: No such file or directory; add --mkpath and rsync creates the whole path (worked on all four versions above).
Step 2: Copy a directory (watch the trailing slash)
A slash at the end of the source means "the contents of this folder". Without it, rsync copies the folder itself into the destination:
$ rsync -av site /backup/ sending incremental file list site/ site/index.php site/cache/ site/cache/page1.html ... $ rsync -av site/ /backup/site-copy/ sending incremental file list created directory /backup/site-copy ./ index.php cache/ cache/page1.html ...
(output shortened). The first command creates /backup/site/; the second puts index.php, cache and the rest straight into /backup/site-copy/. A slash on the destination makes no difference. If you are unsure, add -n first.
Step 3: Sync again: only changes are copied
This is what makes rsync better than cp or scp for backups and site moves. A second run with nothing changed transfers only the file list; after one file changed, only that file is sent:
$ rsync -av site/ /backup/site-copy/ sending incremental file list sent 222 bytes received 15 bytes 474.00 bytes/sec total size is 352,900 speedup is 1,489.03 $ rsync -avh site/ /backup/site-copy/ sending incremental file list index.php sent 2.28K bytes received 38 bytes 4.64K bytes/sec total size is 352.91K speedup is 152.05
For copying only new files, or only files newer than the destination's copy, see How to Rsync Only New or Changed Files in Linux (with Dry Run and Examples).
Step 4: Show progress
-P shows a progress line per file. For one overall progress line for the whole job, use --info=progress2:
$ rsync -ah --info=progress2 site/ /backup/site-p2/
352.01K 100% 25.68MB/s 0:00:00 (xfr#3, to-chk=0/7)
The line updates in place while the copy runs; this is the final state.
Step 5: Copy to or from another server
- Make sure you can log in with
ssh user@serverfirst (with a password or an SSH key). - Push local files to the server:
rsync -avz site/ user@server:/var/www/site/ - Pull files from the server:
rsync -avz user@server:/var/www/site/ site/ - If SSH listens on another port, add
-e "ssh -p 2222". We checked that rsync passes the port on tosshas-p 2222. More on ports: How to Sync Files/Directories Using Rsync with Non-standard SSH Port? and How to Connect to SSH on a Different Port (ssh, scp, sftp, rsync, PuTTY).
The output looks the same as a local copy. If the transfer stops at once with rsync: connection unexpectedly closed (0 bytes received so far) [sender], rsync is usually missing on the other server: install it there. According to the rsync manual, it does not copy between two remote hosts in one command: log in to one of them and run rsync from there.
Step 6: Make an exact mirror with --delete (dry run first)
By default rsync never deletes anything in the destination. To make the destination an exact copy, add --delete, but always preview it with -n, because a wrong path deletes real files:
$ rsync -avn --delete site/ /backup/site-copy/ sending incremental file list deleting css/style.css css/ sent 212 bytes received 42 bytes 508.00 bytes/sec total size is 352,008 speedup is 1,385.86 (DRY RUN)
If the list is what you expect, run the same command without -n.
Step 7: Leave out files and folders
$ rsync -av --exclude=cache/ site/ /backup/site-nocache/ sending incremental file list created directory /backup/site-nocache ./ index.php css/ uploads/ uploads/logo.png
(output shortened). Repeat --exclude for more patterns, for example --exclude=cache/ --exclude='*.log'.
Next steps
- 13 rsync Command Examples for Linux: more rsync examples.
- How to Copy Files with Permissions in Linux (cp -p, rsync -a and chmod --reference): keep permissions and owners when copying.
- Back up your files with rsync and a VPS: automatic backups of your files to a VPS with rsync.
- How to Copy Folders with scp -r (Recursive Copy over SSH): when a one-off
scp -ris enough.
Official documentation: rsync(1) manual.