How to Use the rsync Command to Transfer Files

How to Use the rsync Command to Transfer Files

- 4 mins

What is rsync command?

Install rsync

apt install rsync -y 
   $whereis rsync
   $command -v rsync
   $rscyn --help

Example rscyn Using

  1. I will sycn my local PC (Mac Book) test folder to QEMU Debian 10 VM’s backup folder.
  2. Create the folders.
  3. Create sample text files on Your source.

rsync You should have ^^^

  1. Now We are ready to test rsync command from test/ -> /home/guney/backup/
  2. rsync has –dry-run feature ,It is really usefull beacuse You can see output before actual changes. We are going to test with dry run first. We can say It is a demo mode.
  3. We should use -r (recursive) option If You want to copy folder as We do.
   $ rsync -r --dry-run test guney@192.168.64.15:/home/guney/backup
  1. Here you can see our command but after run this command You will relaize that nothing change or You don’t have any output. Like below rsync1

  2. The reason of you did not see anything, firdt you need to use -v (verbose) flag for see the output and sure You used –dry-run It is not going to perform the changes.
  3. Let’s add the -v to command and see the output. rsync2

  4. Yes, We can see the dry run output now and If We good to go then We can remove –dry-run, run it again and Let’s see What happens. rsync3
  5. We succesfully sync test file to our target.
  6. Let’s try another important feature of rsync. If you renamed file/s on your source directory then What rsync Would do. Let’s test it.
  7. Renamne a file then run the last command. rsync4
  8. Here as You can see there is a problem I renamed test1.txt to test4.txt and run same command after that my backup folder did not updated rsync just send my files over it. It just copied the file and did not replace the original one, It’s not a true sync, rsync revome anything from target default.
  9. Now I just wanted to mention this because again, It is not a sync utility despite the name, e you can sync directories but it is not a sync solution in way that We think of them now.
  10. We should use –delete for delete anything in the target that does not exist at the source directory. rsync6
  11. Both directory have same concents, but it’s still not completly the same. If you check the files modified date. They won’t match and that bring us to the most popular rsync option of all, the dash A option.
  12. -A option is archive mode. It is using for same metadatas
   $ rsync -rva --delete test guney@192.168.64.15:/home/guney/backup
  1. Another option which I want to mentioned is zip option -z, If you use -z option compress the files as they transfer You can use When you have slower connection.
   $ rsync -rvaz --delete test guney@192.168.64.15:/home/guney/backup
  1. Lastly I want to mention –remove-source-files option uses for removed source files after sync.
   $ rsync -rva --remove-source-files test guney@192.168.64.15:/home/guney/backup

That’s all fellas , Hope It helps your works.


:metal: :metal: :metal: :metal: :metal: :metal: :metal:


:memo: Thanks for reading.

Guneycan Sanli.


Guneycan Sanli

Guneycan Sanli

A person who like learning, music, travelling and sports.

comments powered by Disqus