Skip to content

rsync Linux Command Guide

The rsync command in Linux is a powerful tool used for efficient file synchronization and data backup. It allows users to copy and synchronize files and directories locally or between different systems. With its numerous options and capabilities, rsync provides users with flexibility and control over the synchronization process. Whether you need to mirror data, create backups, or transfer files securely, rsync is a versatile solution for managing your data effectively.

rsync Syntax:

Terminal window
rsync [option] [source] [destination]

Options:

OptionDescription
-vVerbose - increase verbosity
-aArchive mode - preserve symbolic links, special and device files, modification times, group, owner, and permissions
-zCompress file data during the transfer
-uSkip files that are newer on the receiver
-rRecursive - copy directories recursively
-hOutput numbers in a human-readable format
-PShow progress during transfer

Parameters:

ParameterDescription
sourceSpecifies the source directory or file to sync
destinationSpecifies the destination directory or file

rsync Command Samples:

Copy Files and Directories Locally

Terminal window
rsync -av /path/to/source /path/to/destination

Copy files and directories from a source to a destination on the same machine.

Synchronize Files and Directories on Remote Server

Terminal window
rsync -avz -e ssh /path/to/source remote_username@remote_host:/path/to/destination

Synchronize files and directories from a local machine to a remote server using SSH.

Exclude Files or Directories

Terminal window
rsync -av --exclude 'file.txt' /path/to/source /path/to/destination

Copy files and directories while excluding specific files or directories.

Show Progress During Transfer

Terminal window
rsync -av --progress /path/to/source /path/to/destination

Display the transfer progress while copying files and directories.

Delete Files in Destination Not Present in Source

Terminal window
rsync -av --delete /path/to/source /path/to/destination

Synchronize files and also delete any files in the destination that are not in the source.

Preserve File Permissions

Terminal window
rsync -av --perms /path/to/source /path/to/destination

Preserve the file permissions while copying files and directories.

Limit Bandwidth Usage

Terminal window
rsync -av --bwlimit=1000 /path/to/source /path/to/destination

Limit the bandwidth used by rsync during the file transfer.

How do I use rsync in Linux?

To use the rsync command in Linux, execute the following command:

Terminal window
rsync --options <source> <destination>

What is the purpose of rsync in Linux?

The rsync command is used in Linux for efficient file synchronization and transfer between a source and a destination. It can be used locally or over a network.

How can I exclude certain files or directories when using rsync?

To exclude specific files or directories during an rsync operation in Linux, use the --exclude option followed by the file or directory you want to exclude. For example:

Terminal window
rsync --options --exclude=filename <source> <destination>

Can rsync be used to copy files between two remote servers?

Yes, rsync can be used to copy files between two remote servers by specifying the remote locations using the user@host: syntax. For example:

Terminal window
rsync --options user1@host1:/path/to/source user2@host2:/path/to/destination

How can I enable compression during rsync to speed up file transfer?

To enable compression during an rsync operation in Linux, use the -z or --compress option. This can help speed up the file transfer process, especially when transferring large files or over a slow network.

Terminal window
rsync --options -z <source> <destination>

Is it possible to preserve file permissions and timestamps with rsync?

Yes, it is possible to preserve file permissions and timestamps during an rsync operation in Linux using the -a or --archive option, which stands for archive mode. This option ensures that all file attributes are preserved.

Terminal window
rsync --options -a <source> <destination>

Applications of the rsync command

  • Synchronizing files and directories between local and remote computers
  • Backing up data securely over a network
  • Mirroring data from one location to another
  • Uploading files to a remote server
  • Maintaining a consistent copy of data across multiple devices or locations