![]() |
My Top 3 |
![]() |
Very important think when you are a programmer is to have the ablility and tools to synchronize your code on multiple locations.
For example you can have a development version a test version and a production version of the code, and you will want all of these versions to be synchronized.
One way of doing that in Unix operating systems is by using the rsync command.
Rsync is a free open source project.
In order to use this command you have to install it first. This article will not go into the installation procedure. You will have to download rsync from the official site and install it on your unix operating system.
Usage examples
Rsync is a very efficient command because it uses a special protocol (rsync remote-update protocol) to synchronize files. It only synchronizes the differences between files, not the all files, which makes it very fast.
The command can be used to synchronize files/folders on a local computer and between remote computers.
The command has the following syntax:
rsync [options] src - see available options bellow
You must specify a source and a destination, one of which may be remote.
Perhaps the best way to explain the syntax is with some examples:
- rsync *.php foo:src/
this would transfer all files matching the pattern *.php from the current directory to the directory src on the machine foo.
- rsync -avz foo:src/my_web_site /data/tmp
this would recursively transfer all files from the directory src/my_web_site on the machine foo into the /data/tmp/my_web_site directory on the local machine. The files are transferred in “archive” mode, which ensures that symbolic links, devices, attributes, permissions, ownerships etc are preserved in the transfer. Additionally, compression will be used to reduce the size of data portions of the transfer.
- rsync -avz /data/tmp
a trailing slash on the source changes this behavior to transfer all files from the directory on the machine foo into the /data/tmp/. A trailing / on a source name means “copy the contents of this directory”. Without a trailing slash it means “copy the directory”. This difference becomes particularly important when using the –delete option.
You can also use rsync in local-only mode.
rsync -avz *.php /home/dev/src/
The above line means synchronize all the php files from the current local directory to the “/home/dev/src/” local directory, and preserve all file/folder attributes.
The most interesting option that rsync has is the ability to use the command only to see what the diffrences are between two destinations. You can do that by sing the -n option.
rsync -navz *.php /home/dev/src/
The above line will only display the differences between the current folder and the “/home/dev/src/” folder, but it will not make any changes. This is very useful if you want to see what files you have worked on or which files were changed.
Available options
There are all the available options in rsync.



Leave a Reply