Need a fast and efficient way to synchronize files on two systems? Looking for an alternative to
RSYNC is the right tool for it!
RSYNC's syncing capability makes it an excellent alternative to FTP and other file transfer tools like
RCP. Why would one want to use
RSYNC for file transfer? It is efficient (does not transfer files which are already in sync), safe (uses SSH), and offers a lot of useful capabilities that FTP and other tools don't offer easily. Maybe FTP is disabled on the server because of security concerns?
In this tutorial, I will show you some of the most common use cases of
Upload all the contents of the current directory to `/home/captain/websites/ahoy` on 192.168.13.37. Enter the password for the user when prompted for it.
$ rsync -zvr ./ email@example.com:/home/captain/websites/ahoy
Upload files and show the progress
$ rsync -zvr --progress ./ firstname.lastname@example.org:/home/captain/websites/ahoy
Delete files that don't exist in the local copy
$ rsync -zvr --delete ./ email@example.com:/home/captain/websites/ahoy
Upload files but exclude some files and directory
We want to exclude all files starting with a dot `.`, and a directory named `node_modules`.
$ rsync -zvr --exclude=".*/" --exclude node_modules/ ./ firstname.lastname@example.org:/home/captain/websites/ahoy
RSYNC options can be used together
$ rsync -zvr --delete --progress --exclude=".*/" --exclude node_modules/ ./ email@example.com:/home/captain/websites/ahoy
Use a public key (.pem file) with RSYNC
We will used a public key named `server-key.pem` instead of supplying a password to authenticate. The key is in the current directory in this case.
$ rsync -zvr -e "ssh -i server-key.pem" ./ firstname.lastname@example.org:/home/captain/websites/ahoy
We will download the contents of the directory `/home/captain/websites/ahoy` on 192.168.13.37 to the current directory. The directory `ahoy` will be created in the current directory with all its contents.
$ rsync -zvr --progress --exclude=".*/" email@example.com:/home/captain/websites/ahoy ./
Wondering what the options
z - compress data (faster transfer)
v - verbose
r - recurse into directories
That should be enough for most basic RSYNC requirements. If you want to know more, open a terminal and type
Note: if you are using
RCP, it is high time you switched to
RSYNC - because
RSYNC was written specifically to replace them.