10 examples of using the rsync command
It is a replacement command, more modern and effective than scp
rsync is a widely used utility for keeping copies of a file on two computer systems at the same time.
It is commonly found on Unix-like systems and in functions such as a file synchronization and file transfer program. The rsync algorithm, a type of delta encoding, is used to minimize network usage.
Zlib can be used for additional compression and SSH or stunnel can be used for data security.
Rsync is open source under the terms of the GNU GPL Version 2.
To install Rsync on your Distro, examples:
Now on to the examples!
01. Copying local file
Similar to cp command
02. Copying verbosely
That is, requiring details of the operation
03. Copying directories recursively
The parameter is
--recursive, but now it’s good to use all commands with
04. Creating directory during copy
The problem with example 03 is that the my-dir directory will not be created and the files will be scattered around.
The correct thing is to use it creating the directory:
05. Copying a remote file to your system
Or specifying your username and also verbose:
06. Copying a remote directory
Just as in scp you need to use
-r, for this remote case you don’t need
--mkpath, directories will be created automatically.
07. Copied with wildcards
We know that you can use
* to copy glob style, which is not regex. So to copy only the txt files from the remote root directory.
Remembering that the directory will not be created.
08. Using progress bar
scp, if you cancel the copy the local file will no longer exist, that is, it does not copy pieces, it is always synchronously.
09. Setting the copy speed
Remote copying within the network also consumes bandwidth based on the speed of your network card, so in order for you to continue using the network or the internet without slowing it down, sometimes it is interesting to limit the speed of the copy, for this you can use the
--bwlimit=[number] parameter, where the [number] will be in kilobits .
The speed will not be exactly 64k, but it will be around, a little above or below, for example:
10. Manual and help
And finally, we are left with the manual and help, because there are still many parameters!