Free Trial

Free VPS Trial, no credit card required

Start Free Trial
How To Copy or Transfer Files on Linux Servers with RSync

How To Copy or Transfer Files on Linux Servers with RSync

NetShop ISP

NetShop ISP · Blog Author

Nov 10, 2021 · Tutorials

Nowadays Linux system admins have a lot of tools and options to facilitate the transfer of data and files from and to servers. SSH and FTP are the most popular protocols for data transfer. FTP, in one hand, is popular due to its ease of use but, on the other hand, SSH is far more secure and reliable.

For SSH-based data transfer scp and sftp are two specialized tools used by system admins for many years. However, none of these offer all the features and capabilities that rsync provides.

In this tutorial we will explain how Rsync works and how you can use it for transferring files and folders from and to Linux Servers. In the end of this tutorial you can also find an Rsync Cheat Sheet with explanation of rsync command parameters.

What is RSync

rsync is a utility for efficiently transferring and synchronizing files between computers and servers across local and public networks (source: Rsync stands for “remote sync” and it uses an algorithm that minimizes the amount of data copied by only transferring files which have changed.

How to Install Rsync on Linux Server

To install Rsync on your Linux server, you can use the following commands below according to your Linux distribution:

sudo apt-get install rsync // for Debian/Ubuntu
pacman -S rsync // for Arch Linux
sudo dnf install rsync // for Fedora/CentOS/RHEL and Rocky Linux/AlmaLinux

Example 1: Copy an Entire Directory from Local Server to a Remote Server

Assuming you are connected on a Server A and you wish to transfer an entire directory named public_html which is under “/home” to a Server B (IP:, you can use the following command:

rsync -arvzh /home/public_html root@

Example 2: Copy a Directory from Remote Server to a Local machine

The following command will help you sync the entire directory /var/backup from a remote server (IP: to a server you are currently connected:

rsync -arvzh root@ /var/

Example 3: Use RSync for Files Transfer between Servers with Custom SSH Port

If you wish to transfer files to a Server which uses a non-standard SSH Port, then you need to supply the rsync command with the -e argument and specify the custom SSH port that the destination server uses. In our example below we assume that the SSH port is 2222, and we are going to transfer the file /home/public_html/index.html.

rsync -avzh -e 'ssh -p 2222' /home/public_html/index.html root@

Example 4: Automatically Delete Files on Source Server after Successful Transfer

In cases when you are initiating data transfer for, lets say, backup purposes you may want to have the files on the originating server deleted after they have been transferred to the backup/destination server.

rsync -avzh --remove-source-files /root/backup.tar.gz root@

Example 5: Test RSync Command with Dry Run

If you are not yet familiar with rsync, you may not want to execute commands that may mess up your data on source or destination servers. In this case, rsync provides a wonderful parameter that will not make any real changes but instead will show the output of what your command would do.

rsync -avzh --dry-run /root/backup.tar.gz root@

Sample Output:

[root@ubuntu-server:~]# rsync --dry-run --remove-source-files -zvh /root/backup.tar.gz root@

root@'s password: 

sent 50 bytes  received 94 bytes  95.15 bytes/sec
total size is 267.30K  speedup is 3,873.97 (DRY RUN)

Rsync Cheat Sheet

Here is a cheat sheet for all rsync’s arguments which you may need to supply in your command for data transfer/sync.

-v–verboseincrease verbosity
-q–quietsuppress non-error messages
–no-motdsuppress daemon-mode MOTD (see caveat)
-c–checksumskip based on checksum, not mod-time & size
-a–archivearchive mode; equals -rlptgoD (no -H,-A,-X)
–no-OPTIONturn off an implied OPTION (e.g., –no-D)
-r–recursiverecurse into directories
-R–relativeuse relative path names
–no-implied-dirsdon’t send implied dirs with –relative
-b, –backupmake backups (see –suffix & –backup-dir)
–backup-dir=DIRmake backups into hierarchy based in DIR
–suffix=SUFFIXbackup suffix (default ~ w/o –backup-dir)
-u–updateskip files that are newer on the receiver
–inplaceupdate destination files in-place
–appendappend data onto shorter files
–append-verify–append w/old data in file checksum
-d–dirstransfer directories without recursing
-l–linkscopy symlinks as symlinks
-L–copy-linkstransform symlink into referent file/dir
–copy-unsafe-linksonly “unsafe” symlinks are transformed
–safe-linksignore symlinks that point outside the tree
-k–copy-dirlinkstransform symlink to dir into referent dir
-K–keep-dirlinkstreat symlinked dir on receiver as dir
-H–hard-linkspreserve hard links
-p–permspreserve permissions
-E–executabilitypreserve executability
–chmod=CHMODaffect file and/or directory permissions
-A–aclspreserve ACLs (implies -p)
-X–xattrspreserve extended attributes
-o–ownerpreserve owner (super-user only)
-g–grouppreserve group
–devicespreserve device files (super-user only)
–specialspreserve special files
-Dsame as –devices –specials
-t–timespreserve modification times
-O–omit-dir-timesomit directories from –times
–superreceiver attempts super-user activities
–fake-superstore/recover privileged attrs using xattrs
-S, –sparsehandle sparse files efficiently
-n–dry-runperform a trial run with no changes made
-W–whole-filecopy files whole (w/o delta-xfer algorithm)
-x–one-file-systemdon’t cross filesystem boundaries
-B–block-size=SIZEforce a fixed checksum block-size
-e–rsh=COMMANDspecify the remote shell to use
–rsync-path=PROGRAMspecify the rsync to run on remote machine
–existingskip creating new files on receiver
–ignore-existingskip updating files that exist on receiver
–remove-source-filessender removes synchronized files (non-dir)
–delan alias for –delete-during
–deletedelete extraneous files from dest dirs
–delete-beforereceiver deletes before transfer, not during
–delete-duringreceiver deletes during the transfer
–delete-delayfind deletions during, delete after
–delete-afterreceiver deletes after transfer, not during
–delete-excludedalso delete excluded files from dest dirs
–ignore-errorsdelete even if there are I/O errors
–forceforce deletion of dirs even if not empty
–max-delete=NUMdon’t delete more than NUM files
–max-size=SIZEdon’t transfer any file larger than SIZE
–min-size=SIZEdon’t transfer any file smaller than SIZE
–partialkeep partially transferred files
–partial-dir=DIRput a partially transferred file into DIR
–delay-updatesput all updated files into place at end
-m–prune-empty-dirsprune empty directory chains from file-list
–numeric-idsdon’t map uid/gid values by user/group name
–timeout=SECONDSset I/O timeout in seconds
–contimeout=SECONDSset daemon connection timeout in seconds
-I–ignore-timesdon’t skip files that match size and time
–size-onlyskip files that match in size
–modify-window=NUMcompare mod-times with reduced accuracy
-T–temp-dir=DIRcreate temporary files in directory DIR
-y–fuzzyfind similar file for basis if no dest file
–compare-dest=DIRalso compare received files relative to DIR
–copy-dest=DIR… and include copies of unchanged files
–link-dest=DIRhardlink to files in DIR when unchanged
-z–compresscompress file data during the transfer
–compress-level=NUMexplicitly set compression level
–skip-compress=LISTskip compressing files with suffix in LIST
-C–cvs-excludeauto-ignore files in the same way CVS does
-f–filter=RULEadd a file-filtering RULE
-Fsame as –filter=’dir-merge /.rsync-filter’

repeated: –filter=’- .rsync-filter’
–exclude=PATTERNexclude files matching PATTERN
–exclude-from=FILEread exclude patterns from FILE
–include=PATTERNdon’t exclude files matching PATTERN
–include-from=FILEread include patterns from FILE
–files-from=FILEread list of source-file names from FILE
-0–from0all *from/filter files are delimited by 0s
-s–protect-argsno space-splitting; wildcard chars only
–address=ADDRESSbind address for outgoing socket to daemon
–port=PORTspecify double-colon alternate port number
–sockopts=OPTIONSspecify custom TCP options
–blocking-iouse blocking I/O for the remote shell
–statsgive some file-transfer stats
-8–8-bit-outputleave high-bit chars unescaped in output
-h–human-readableoutput numbers in a human-readable format
–progressshow progress during transfer
-Psame as –partial –progress
-i, –itemize-changesoutput a change-summary for all updates
–out-format=FORMAToutput updates using the specified FORMAT
–log-file=FILElog what we’re doing to the specified FILE
–log-file-format=FMTlog updates using the specified FMT
–password-file=FILEread daemon-access password from FILE
–list-onlylist the files instead of copying them
–bwlimit=KBPSlimit I/O bandwidth; KBytes per second
–write-batch=FILEwrite a batched update to FILE
–only-write-batch=FILElike –write-batch but w/o updating dest
–read-batch=FILEread a batched update from FILE
–protocol=NUMforce an older protocol version to be used
–iconv=CONVERT_SPECrequest charset conversion of file names
–checksum-seed=NUMset block/file checksum seed (advanced)
-4–ipv4prefer IPv4
-6–ipv6prefer IPv6
–versionprint version number
-h–helpshow help

Related Articles


Business Continuity
Cloud Hosting
Company Updates
Data Centers
Dedicated Servers
Disaster Recovery
Industry News
Managed Services
Press Releases
Product News
Software & Apps
Tech Startups
Vps Hosting
Web Design & Development
Web Hosting

Free VPS Trial

No Credit Card Required.

Recent Posts

How to Choose the Right Server for MT4 and MT5 Trading Platforms

How to Choose the Right Server for MT4 and MT5 Trading Platforms

08 August, 2022

How To Achieve Ultra-Low Latency for Online Casino and Sports Betting platforms

How To Achieve Ultra-Low Latency for Online Casino and Sports Betting platforms

03 August, 2022

How to integrate one of the most popular online casino games providers in Cyprus

How to integrate one of the most popular online casino games providers in Cyprus

20 July, 2022

Curacao Government to form a new Online Gambling licensing body

Curacao Government to form a new Online Gambling licensing body

18 July, 2022

How To Connect to your Linux Server via myNetShop Web Console

How To Connect to your Linux Server via myNetShop Web Console

13 July, 2022


Bare Metal Dedicated Servers

Virtual Servers (VPS / VDS)

Rack Space & Colocation Hosting

Fast Web Hosting

Cloud Backup

Premium DNS Hosting








About Us


Awards & Honours

Become a Partner

Contact Us


Award Winning Hosting Provider with a Customer-centric approach to Business and an Open Source Mindset regarding Solutions and Products Development.

Est. 2004, Larnaca – Cyprus


Legal Address: 2A, Marathonos, Livadhia, 7060, Cyprus

Operations Office: 120, Faneromenis Avenue, Imperial Tower, 2nd Floor, Larnaca, 6031, Cyprus

Company Reg: HE 217340
EU VAT Number: CY10217340J
ISO 9001:2015: No. QS.21.038

International Phone: +357 2425 0808