In this tutorial, we will discuss how to transfer files among systems using SCP & Rsync with some examples. We will also discuss SCP & RSYNC command line options to make use of the commands to the fullest.
Also Read: Cloning disks using dd & cat commands
SCP & Rsync commands
SCP is based on ssh & is used to transfer files from localhost to remote host securely.
The syntax for using SCP is
Rsync’s main function, on the other hand, is basically to synchronize files/directories either on localhost or on the remote host. Rsync initially copies the whole directory & then copies the newly added files (differential backup) rather than copying the whole directory again.
It is secure & faster than SCP & can also be used in place of the SCP command to copy files/directories to the remote hosts.
The syntax for using rsync is
Now, let us discuss some examples showing the uses of both commands.
Examples for SCP command line options
here, option r is used when we are copying a directory with all the files inside it,
secondly, option p will provide an estimated time & connection speed,
and option v will provide debugging information that can help in diagnosing a problem related to connection, authentication, etc.
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.
here option –P is used to define a custom port in case we are not using the default ssh port (22).
Get complete list of options that can be used with SCP by running,
Examples for Rsync command line options
here, option r is archive mode which allows copying of files recursively along with their file permissions, symbolic links, etc,
The second option r is used to compress file data,
third option h will provide human-readable outputs,
and option v will provide debugging information that can help in diagnosing a problem related to connection, authentication, etc,
Also, we can mention a local location like /home/dan in place of [email protected]:/home/susan
The above example will let us synchronize a directory from a remote location to the localhost directory & --progress will show us the progress of file/directory transfer.
this example will let us use rsync over ssh and option –e here is used to define a protocol, which in this case is ssh.
here, this example will let us use rsync over ssh with the modified port.
this will let us copy all files starting with "A" & will exclude all other files. Get the complete list of options that can be used with rsync by running the following command,
Both the scp & rsync can be used to transfer files/directories but rsync fares a little better when comes to performance. Also, Rsync command line options allow us to take differential backup which scp can not do. But both are equally secure & very easy to use.
This was our tutorial on how to use SCP & Rsync command line options in Linux. Please do let us know if you have any questions or queries using the comment box below.