Command lines and options of rsync 3.5.1 from the project's own manual page, grouped by task. Option rows show the single-letter form where one exists and name the long form in the usage text; rows that start with rsync are whole commands printed in the manual. A trailing slash on a source directory copies its contents instead of the directory itself. Batch mode, character-set conversion and protocol tuning are left out.
Push with an rsync URLTo contact the daemon directly, leave -e out; with it, rsync starts a daemon through that shell.
Copying directories 8
A trailing slash on the source means the directory's contents; without it the directory itself is created inside the destination. The source directory's attributes are applied in both cases.
Command
What it does
rsync -avz foo:src/bar /data/tmp
Pull a directory by nameWithout a trailing slash the bar directory itself is created, giving /data/tmp/bar, in archive mode with compression.
rsync -avz foo:src/bar/ /data/tmp
Pull a directory's contentsThe trailing slash on the source puts what is inside bar straight into /data/tmp, with no extra bar level.
rsync -av /src/foo /dest
Copy a folder into a parentProduces /dest/foo, the same result as the trailing-slash form that names /dest/foo as destination.
rsync -av /src/foo/ /dest/foo
Copy contents to a named folderEquivalent to the form without slashes; the attributes of /src/foo are applied to /dest/foo either way.
rsync -av host: /dest
Copy a host's default directoryA bare host reference needs no trailing slash: the remote default directory's contents land directly in /dest.
rsync -ai foo/ bar/
Copy a directory under a new nameThe slash after foo sends only its contents, so they fill bar whatever the destination is called.
rsync -ai src/foo.c save/bar.c
Copy a file under a new nameWorks when a single item is sent and save/bar.c is neither an existing directory nor written with a trailing slash.
rsync -ai src/*.c save/dir/
Force a destination directoryThe trailing slash stops a wildcard that matches one file from saving it as a file named save/dir.
Copying remote files 6
Command
What it does
rsync -t *.c foo:src/
Copy matching files to a hostThe shell expands the wildcard; files already on foo are updated by sending only the changed data.
Start remote rsync in a directoryPROGRAM runs through a shell, so a cd first moves the base that -R paths start from.
-z
Compress during transferLong form --compress; helps on slow links, and rsync --version lists the methods your build has.
--compress-choice=STR
Pick a compression algorithmAlso --zc; choices include zstd, lz4, zlibx, zlib and none, and any choice except none turns on -z.
--compress-level=NUM
Set the compression levelAlso --zl; implies -z unless the level means off for the algorithm in use, like 0 for zlib.
-M OPTION
Pass an option to the remote sideLong form --remote-option; for settings such as --log-file that should apply on one side only.
-s
Send arguments via the protocolLong form --secluded-args; names and most options bypass the remote shell's command line, and wildcards are expanded by rsync.
-4
Prefer IPv4Applies to daemon sockets and is forwarded to ssh when rsync can tell ssh is the remote shell.
-6
Prefer IPv6The IPv6 counterpart; other remote shells need their own hint passed inside the -e command.
Connecting to a daemon 8
Command
What it does
rsync somehost.mydomain.com::
List a daemon's modulesNaming the host without a module prints the modules that daemon allows to be listed.
rsync -av host::src /dest
Copy a whole daemon moduleFetches every file of the module called src; protected modules prompt for a password.
rsync -av --rsh=ssh host::module /dest
Reach a daemon module over sshDaemon features over a shell connection need --rsh on the command line; setting RSYNC_RSH does not enable them.
Use separate ssh and module usersWith -l handed to ssh, the user@ prefix only names the account for the module login.
--password-file=FILE
Read the daemon password from a fileA FILE of - means standard input; a world-readable file is refused, and ssh passwords are not covered.
--port=PORT
Use another daemon portOnly needed with the double-colon syntax, since a URL can carry the port; the default is 873.
--contimeout=SECONDS
Limit the daemon connect waitrsync gives up with an error when the daemon connection takes longer than this.
--no-motd
Hide the daemon's welcome messageAlso suppresses the module list of a host-only request, so leave it off when listing modules.
Running a daemon 4
Command
What it does
--daemon
Run rsync as a daemonDetaches into the background unless standard input is a socket, in which case it assumes inetd.
--config=FILE
Use another rsyncd.confOnly relevant with --daemon; the usual default is /etc/rsyncd.conf.
--no-detach
Keep the daemon in the foregroundRequired for a Cygwin service and useful under supervisors such as daemontools.
rsync --daemon -M pidfile=/path/rsync.pid
Override a daemon setting-M (--dparam) sets a global rsyncd.conf parameter at startup, here the location of the pid file.
No row on this page matches that filter.
Notes
The core command
-a is archive mode, the same as -rlptgoD: recursion plus symlinks, permissions, times, group, owner (when the receiver runs as super-user) and device and special files. ACLs, extended attributes and hard links need -A, -X and -H on top. -v lists files and -z compresses file data in transit. A trailing slash on the source means "the contents of": rsync -avz foo:src/bar/ /data/tmp fills /data/tmp, while rsync -avz foo:src/bar /data/tmp creates /data/tmp/bar. A single colon after the host uses a remote shell, normally ssh, and -e 'ssh -p 2234' passes options such as a port to it. --progress shows per-file progress and --bwlimit=RATE caps throughput, in units of 1024 bytes per second when the number has no suffix.
Mirroring safely
--delete removes files in the destination that no longer exist in the source, turning a sync into a mirror. It only acts on directories sent whole (dir or dir/, not dir/*) and needs recursion. Run the same command with -n first, together with -v or -i, to see what would go; --max-delete=NUM caps the number of deletions, and 0 only warns. --backup-dir=DIR moves replaced or deleted files into a backup directory instead of discarding them. --exclude=PATTERN skips matching files (repeatable, or --exclude-from=FILE for a list), and excluded files are also kept safe from deletion unless --delete-excluded is given. --max-size=SIZE skips large files.
Speed and partials
--partial keeps a partially transferred file so the next run finishes it faster, and -P combines it with --progress. --size-only compares by size alone, which helps after a mirroring tool that did not keep timestamps, but it cannot see an edit that leaves the size unchanged. For FAT filesystems, which store times in 2-second steps, the manual suggests --modify-window=NUM with a value of 1 instead. rsync -av --list-only foo* dest/ lists files instead of copying them, which is a quick way to confirm a path before syncing to it.
Questions
Does a trailing slash on the source directory change what rsync copies?
Yes. rsync -avz foo:src/bar /data/tmp creates /data/tmp/bar, while rsync -avz foo:src/bar/ /data/tmp copies only what is inside bar. The attributes of bar are applied in both cases. A bare host or module reference such as rsync -av host: /dest needs no slash to copy contents.
How can I see what --delete would remove before running it?
Add -n (dry run) with -v or -i to the same command: nothing is changed and the itemized output matches what a real run would do. --max-delete=NUM with 0 warns about extraneous files without deleting any.
Why does rsync update every file again on each run?
The quick check compares size and modification time. Without -t (or -a) times are not preserved, so the next run behaves as if -I had been given. On FAT filesystems --modify-window=NUM with 1 absorbs their 2-second time resolution.
How do I resume a large transfer that was interrupted?
Run it with --partial, or -P to add progress output, so a half-copied file is kept and finished on the next run. --partial-dir=DIR keeps such files out of the destination until they are complete. --append-verify suits only files that grow and never change in place.
How do I connect to an ssh server on a non-standard port?
Pass the whole ssh command as one argument: -e 'ssh -p 2234'. Settings in .ssh/config work as well, since rsync starts ssh as its remote shell.