Unison is a file synchronization tool that allows you to keep two or more directories in sync. It is useful for synchronizing files between a local machine and a remote server, or between multiple machines on a local network.
To use Unison, you will need to install it on all machines that you want to synchronize. On Debian-based systems such as Ubuntu, you can install Unison using the following command:
sudo apt-get install unison
On CentOS or Red Hat Enterprise Linux (RHEL), you can install Unison using the following command:
sudo yum install unison
Once Unison is installed, you can use the unison
command to synchronize directories. For example, to synchronize the /home/user/documents
directory on the local machine with the /home/user/documents
directory on a remote server, you can use the following command:
unison /home/user/documents ssh://user@remote-server//home/user/documents
The first time you run Unison, it will ask you to confirm which files to synchronize and which files to ignore. You can specify ignore patterns using the -ignore
option. For example, to ignore all files ending in .bak
, you can use the following command:
unison -ignore '*.bak' /home/user/documents ssh://user@remote-server//home/user/documents
To synchronize multiple directories, you can specify multiple directory pairs separated by a space. For example, to synchronize the /home/user/documents
and /home/user/photos
directories, you can use the following command:
unison /home/user/documents ssh://user@remote-server//home/user/documents /home/user/photos ssh://user@remote-server//home/user/photos
Unison has many other options and features that allow you to customize its behavior. You can learn more about these by running man unison
or by reading the Unison manual at https://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html.