Files transfer using scp & rsync commands

Hello Linux-fanatics, in this tutorial we will discuss how to transfer files among system using scp & rsync with some examples. (also read tutorial on “Cloning disks using dd & cat commands“). But firstly let’s discuss both commands in brief.

scp & rsync commands

scp is based on ssh & is used to transfer file from local host to remote host securely.  Syntax for using scp is

scp source_file_name username@destination_host:destination_folder

Rsync’s main function, on the other hand is basically to synchronize files/directories either on local host or on remote host. Rsync initially copies whole directory & then copies newly added files (differential backup) rather than copying whole directory again.

It is secure & faster than scp & can also be used in place of scp command to copy files/directories to remote host. Syntax for using rsync is

rsync options source destination

Now, let us discuss some examples  showing uses of both commands.


Examples for scp


scp –rpv /datafile dan@

here, option r is used when we are copying a directory with all the files inside it,

secondly option p will provide an estimate time & connection speed,

and option v will provide debugging information which can help in diagnosing a problem related to                              connection, authentication etc.

scp –C /datafile dan@

option C here will compress the file on the go & will reproduce the same file when it arrives at the destination. Thus saving time consumed for copying the file.

scp –P 300 /datafile dan@

here option –P is used to define a custom port incase we are not using default ssh port (22).


Examples for Rsync


rsync –azvh /datafile dan@

here, option r is archive mode which allows copying of files recursively along with their file permissions, symbolic links etc,

Second option r is used to compress file data,

third option h will provide human readable outputs,

and option v will provide debugging information which can help in diagnosing a problem related to connection, authentication etc,

Also, we can mention alocal location like /home/dan in place of dan@

rsync -azvh – -progress dan@ /datafile

above example will let us synchronize a directory from remote location to local host directory & –progress will show us the progress of file/directory transfer.

rsync –avzhe ssh /datafile dan@

this example will let us use rsync over ssh and option –e here is used to define a protocol , which is this case is ssh.

rsync –avzhe ‘ssh –p 300’ /datafile dan@

here, this example will let us use rsync over ssh with modified port.

rsync -azvh – -progress –include ‘A*’ –exclude ‘*’ dan@ /datafile

this will let us copy all files starting with “A” & will exclude all other files.


Both the scp & rsync can be used to transfer files/directories but rsync fares a little better when comes to performance. Also rysnc has option to take differential backup which scp lacks. But both are equally secure & very easy to use.

Don’t forget to leave your comments/queries in the comment box. ADIOS!!!

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.


Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

2 Responses

  1. Philip Miller says:

    This is very good but it does not work with AWS servers. Still missing public keys. How to identify the public key on the sending and receiving servers.

Leave a Reply

Your email address will not be published. Required fields are marked *