Skip to content

Tools

Sync two folders (bidirectional synchronization)


Install

Terminal window
sudo dnf install unison

Initial sync

Terminal window
unison /path/to/folderA /path/to/folderB -auto -batch
  • if folderA has context, folderB is empty —> folderB will be filled in folderA stuff
  • if both folders have different files already, unison will merge them

-auto : Automatic Mode. Unison automatically resolve non-conflicting changes. If a file is new or unchanged in both locations, Unison will sync it without asking.

-batch : Fully Automatic Mode. this makes Unison completely non-interactive. It assumes the latest modified version wins and resolves all conflicts automatically.

If meeting permission issue: Then don’t sync permission

Terminal window
unison /path/to/folderA /path/to/folderB -auto -batch -perms 0

Build connection

Sync every xx seconds

while true; do unison /path/to/folderA /path/to/folderB -auto -batch; sleep 5; done
This is a Bash infinite loop that repeatedly runs Unison every 5 seconds

  • do: marks the beginning of the loop body
  • done: marks the end of the loop body

everything between do and done runs once per loop iteration

  • sleep 5: pauses execution for 5 seconds before restarting the loop
    this is only good for syncing across network drives (NFS, SSH etc)

Watch mode

(terminal open, stop when terminal window close)
Monitor file changes in real-time and sync only when necessary

Terminal window
unison /path/to/folderA /path/to/folderB -auto -batch -repeat watch

-repeat watch: enables watch mode , detecting changes in real-time


Run as a Background Service

Instead of keeping a terminal open, create a systemd service:

Terminal window
sudo nano /etc/systemd/system/unison-sync.service

Paste:

[Unit]
Description=Unison Sync Service
After=network.target
[Service]
ExecStart=/usr/bin/unison /home/j/projects/digital-debris/src /mnt/D/blog/digital-debris/src -auto -batch -repeat watch -silent -prefer newer -perms 0
Restart=always
User=j
Group=j
WorkingDirectory=/home/j
[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reload sudo systemctl restart unison-sync sudo systemctl enable —now unison-sync`

This makes Unison run in the background automatically.

check Unison status:

Terminal window
systemctl status unison-sync

Stop Unison if needed

Terminal window
sudo systemctl stop unison-sync

Disable it permanently

Terminal window
sudo systemctl disable unison-sync

Break connection

If Unison is running in a loop, kill it:
For example : in while true —> execute pkill unison

Remove Synchronization Metadata:
rm -rf ~/.unison


Change background color (solid color) on Gnome

reference link

  • launch dconf Editor — dconf-editor
  • Go to /org/gnome/desktop/background/
  • if you have a picture: go to picture-url, change Custom value to none
  • if not, just change the color: go to primary-color, change Custom value to desired one