Using Unison for Two-Way File Synchronization on Linux

Using Unison for Two-Way File Synchronization on Linux

- 7 mins

A Step-by-Step Guide to Installing and Using Unison for Two-Way File Synchronization on Linux

Keeping files synchronized between multiple Linux systems is something many of us eventually need—especially if you move between a laptop and desktop, keep a home lab, or work on projects from both a personal and a remote server.

Simple backup tools like rsync are great, but they only move data in one direction. If you modify files on both systems, you can easily overwrite something important.

This is exactly why I personally use Unison, a powerful two-way file synchronizer. It compares both sides, detects what changed where, and keeps everything consistent.

Below is my complete step-by-step guide on installing and using Unison effectively, including helpful examples and tips from real use.


What You Will Learn

Let’s begin!


1. Installing Unison on Your Linux System

Unison is available in most official repositories, so installation is straightforward.

sudo apt install unison  
sudo dnf install unison  
sudo apk add unison  
sudo pacman -S unison  
sudo zypper install unison  
sudo pkg install unison  

GUI Version (Optional)

Available only on Debian-based distributions:

sudo apt install unison-gtk

Check your installed version

unison -version

unison

Important Version Warning

Unison requires both machines to use the same version.
If your local system has Unison 2.53.3 and your server has 2.48, they will refuse to sync.

This is one of the most common beginner problems—so always check versions on both ends.


2. Local Folder Synchronization (Beginner-Friendly Start)

Before jumping into remote syncing, I always recommend practicing with two local folders.

Let’s say I have:

unison

Run your first sync

unison ~/test/test_file  ~/sync/test_file_backup

unison

What happens during this process?

  1. Unison scans both directories
    It looks at file names, sizes, and modification timestamps.

  2. Changes are listed
    You’ll see which files are new, updated, or conflicting.

  3. Unison asks what to do
    Copy from left to right? Right to left? Skip?

  4. Synchronization happens
    Both folders become identical after confirming actions.

Good to know


3. Synchronizing Files Between server and remote server (SSH)

Once you’re comfortable with local sync, it’s time to sync with another machine.
Let’s assume I want to sync my local “test” folder with a folder on my server.

Example Command

unison ~/test ssh://guney@192.168.1.151//home/guney/sync

unison

unison

unison

Explanation

Tip: Use SSH keys

I strongly recommend setting up SSH key authentication so you don’t have to enter your password every time.


4. Creating Unison Profiles (Automation Made Simple)

Typing the full sync command each time gets tiring.
Profiles allow you to save configuration files that run with a single word.

Create a profile

vi ~/.unison/testsync.prf

Example profile configuration

root = /home/guney/test
root = ssh://guney@192.168.11.151//home/guney/sync

auto = true
batch = true
prefer = newer

unison

What each setting does:

Run using profile

unison testsync

unison

Much easier, right?


5. Live Syncing with Watch Mode (Real-Time Monitoring)

If you’re working on a project and want changes to sync automatically without manual commands, you can use:

unison testsync -repeat watch

Note: It did not work in my tests, I am searching probably the version of my unison

This runs Unison in continuous watch mode:

Note

For very large directories, watch mode may consume noticeable system resources.
Use it only when necessary.


6. Scheduling Automatic Syncs with Cron

If you prefer periodic sync instead of continuous watch mode, you can use cron.

Edit your crontab

crontab -e

Example: Sync every hour

0 * * * * unison testsycn -batch

This runs your “testsycn” profile non-interactively every hour.


7. Useful Unison Options (Cheat Sheet)

Option Description
-auto Automatically handles simple updates
-batch No user prompts (cron-friendly)
-ui text Forces text interface
-repeat watch Real-time sync
-prefer newer Newest file wins in conflicts

Combined example

unison work -auto -batch -prefer newer


8. Why I Prefer Unison Over Other Tools

Tool Sync Type Two-Way GUI Best Use
rsync One-way Backups, mirroring
Unison Two-way Optional Active development, multi-system workflows

Unison gives me flexibility rsync never could.
I can edit files on either machine knowing nothing will be overwritten incorrectly.


Final Thoughts

Unison is one of the most reliable and efficient tools for two-way synchronization on Linux.
Once you get your first profile working, it becomes incredibly convenient—especially for people like me who work across multiple systems every day.

Whether you want automatic backups, mirrored development environments, or fast syncing between your laptop and server, Unison is a tool worth mastering.


Thanks for reading!

Guneycan Sanli

Guneycan Sanli

Guneycan Sanli

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

comments powered by Disqus