How to move files using ‘rsync’ command in linux

Posted on

This article will display on how to move files using ‘rsync’ command in linux operating system. The command itself is mainly useful for moving files from one place to another. It can be in the different location within a device, or a server or it can be totally between two different server or device. The main advantage using the ‘rsync’ command is because it can detect and compare the files in the source and also in the target destination.

It can automatically erase or remove the files in the source if there is already an identical file in the target destination.

In order to delete, erase or remove the source files, there is an additional specific parameter in using the commmand. The following is the command for moving the files normally :

rsync -avz [source] [target]
Information : 
-a : archive
-v : verbose, displaying all the output of the command 
-z : compress, it means compress the file data during transfer

First of all, the additional parameter ‘-avzx’ is a normal parameter. In order to remove all the files in the source after it fully moved to the target or destination, just add the following additional parameter :

--remove-source-files

But as a precatious step, the simulation of the process is possible by adding some sort of additional parameter. That additional parameter is ‘–dry-run’. So, the perform for simulating the movement of those files is possible with the following command :

rsync --dry-run --remove-source-files -avz [source] [target]

After successfully executing the simulation for moving the above files from source to the destination, just do the real one. Do it by omitting the ‘–dry-run’ additional parameter. So, the final command for achieving the goal is as follows :

rsync --remove-source-files -avz [source] [target]

Leave a Reply