Skip to main content
Transfer and Synchronize Files:

Rsync cheat sheet

Summary

This cheat sheet provides a basic overview of the rsync command for local and remote file synchronization. It includes command syntax, option explanations, and detailed examples for common use cases.

Introduction #

rsync is a command-line tool for synchronizing and transferring files and directories. Use it for backups, remote file synchronization, and incremental transfers.

This cheat sheet provides a concise summary of rsync command options along with detailed examples for each option.

Synopsis #

Local copy #

The following form is used to copy files and directories locally on the same machine:

rsync [OPTION...] SRC... [DEST]

SRC can be one or more source paths, and DEST is the target path. If DEST is a directory, all sources are copied into it. If DEST is omitted and only one source is specified, rsync lists the files in the source path instead of copying.

Remote copy via shell #

The following mode uses a remote shell like Secure Shell (SSH) to transfer files between local and remote machines:

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

Push:
    rsync [OPTION...] SRC... [USER@]HOST:DEST
  • Pull copies files from a remote host to the local machine.
  • Push copies files from the local machine to a remote host.

USER is optional and specifies the remote username. HOST is the remote machine address. The default remote shell is SSH but can be changed with the -e option.

Remote copy via rsync daemon #

The following mode connects to a running rsync daemon on a remote machine:

Pull:
    rsync [OPTION...] [USER@]HOST::SRC... [DEST]
    rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]

Push:
    rsync [OPTION...] SRC... [USER@]HOST::DEST
    rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
  • Pull copies files from the rsync daemon to the local system.
  • Push copies files from the local system to the rsync daemon.

Double colons (::) or rsync:// syntax is used instead of single colons to indicate daemon access. You can optionally specify USER for authentication and PORT if the daemon is listening on a non-default port.

Directory listing mode: If only a single source (SRC) is specified without a destination (DEST), rsync will list the contents of that source instead of copying files. This works for both local and remote sources and is useful for verifying file availability.

rsync command options #

OptionDescription
-aArchive mode: recursive, preserves symbolic links, permissions, etc.
-vVerbose output
-zCompress file data during transfer
-hOutput numbers in a human-readable format
-rRecursive into directories
-uSkip files that are newer on the receiver
--progressShow progress during transfer
--deleteDelete files from destination that are not in source
--dry-runShow what would have been transferred
-e sshUse Secure Shell (SSH) for remote shell
--excludeSkip files matching a pattern
--includeDo not exclude files matching a pattern
-LCopy the referent of symbolic links
--bwlimitLimit bandwidth usage in kilobytes per second
--checksumUse checksums to determine if files need to be updated

Examples and explanations #

Basic local copy #

The following rsync command copies files from /source/dir/ to /destination/dir/. The trailing slash in the SRC ensures only the contents of /source/dir/ are copied, not the directory itself:

rsync -avh /source/dir/ /destination/dir/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.

Remote copy over SSH #

The following rsync command uploads the contents of /local/dir/ to /remote/dir/ on remote-host over a Secure Shell (SSH) connection:

rsync -avz -e ssh /local/dir/ user@remote-host:/remote/dir/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -z compresses file data during transfer, which is useful over slower network connections.
  • -e ssh specifies that SSH should be used for the remote shell.

Show transfer progress #

The following rsync command copies /source/file to /destination/file and displays a progress bar during the transfer:

rsync -avh --progress /source/file /destination/file
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --progress shows real-time progress, including percentage complete, transfer speed, and estimated time remaining.

Dry run mode #

The following rsync command simulates copying files from /source/ to /destination/ without actually transferring any data:

rsync -avh --dry-run /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --dry-run prevents changes from being made and instead displays which files would have been copied.

Exclude files #

The following rsync command copies all files from /source/ to /destination/ except those that match the pattern *.log:

rsync -avh --exclude '*.log' /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --exclude '*.log' tells rsync to skip any files ending with .log.

The wildcard * applies recursively within subdirectories.

Include specific files and exclude others #

The following rsync command copies only .txt files from /source/ to /destination/ and ignores all other files:

rsync -avh --include '*.txt' --exclude '*' /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --include '*.txt' includes files ending in .txt.
  • --exclude '*' excludes everything else.

Order matters: includes must be specified before excludes to override them.

Delete extraneous files #

The following rsync command deletes files in /destination/ that do not exist in /source/, ensuring both directories are mirror images:

rsync -avh --delete /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --delete removes files from the destination that are absent from the source.

Use --dry-run with --delete first to preview what would be removed.

Use checksum comparison #

The following rsync command compares file contents using checksums instead of relying on file size and modification time. This is slower but ensures more accurate detection of file changes:

rsync -avh --checksum /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --checksum forces a full checksum comparison to determine if files differ.

Skip newer destination files #

The following rsync command skips transferring files that are newer in the destination than in the source:

rsync -avh -u /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • -u stands for “update” and prevents overwriting newer files in the destination.

Bandwidth limit #

The following rsync command limits the transfer rate to 1000 kilobytes per second:

rsync -avh --bwlimit=1000 /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • --bwlimit=1000 throttles the bandwidth used during the transfer to avoid network congestion.

Combine this with `--progress` to monitor throttled transfers.

The following rsync command copies the files pointed to by symbolic links instead of the links themselves:

rsync -avh -L /source/ /destination/
  • -a enables archive mode, preserving symbolic links, file permissions, and timestamps.
  • -v enables verbose output.
  • -h enables human-readable output.
  • -L (or --copy-links) tells rsync to follow symbolic links and copy the actual files they reference.

Recursive copy without metadata preservation #

The following rsync command performs a recursive copy of all files and subdirectories from /source/ to /destination/, without preserving symbolic links, file permissions, timestamps, or other metadata:

rsync -rv /source/ /destination/
  • -r enables recursion into subdirectories.
  • -v shows what files are being transferred.

FAQ's #

Most common questions and brief, easy-to-understand answers on the topic:

Can I use rsync to transfer files over SSH?

Yes. You can use SSH with rsync by adding the -e ssh option or using a remote target like user\@host:/path.

Does rsync copy symbolic links or follow them?

By default, rsync copies the link itself. Use -L to follow symbolic links and copy the actual files they point to.

How do I perform a dry run with rsync?

Use the --dry-run option. It shows what would be transferred without actually copying files.

How do I exclude files from an rsync transfer?

Use the --exclude option followed by a pattern, for example --exclude '\*.log' to skip all log files.

Is rsync faster than scp for large transfers?

Yes. rsync transfers only the differences between source and destination files, making it faster and more efficient than scp in many cases.

Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

Rsync cheat sheet by Jonas Jared Jacek is licensed under CC BY-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/rsync-cheat-sheet">Rsync cheat sheet</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>

For more information see the Ditig legal page.

All Topics

Random Quote

“Obey standards unless you've a darn good reason.”

Alan Cooper  Software designer and programmerAbout Face, - IT quotes