Merge directories with unison-gtk - gHacks Tech News

Merge directories with unison-gtk

Yesterday, at the office, we had a client come to use needing to merge two 20 Gig directories of data together. Naturally I chimed in saying "I'm sure Linux can do that with a simple shell script"! Of course neither the client or my fellow workers wanted to deal with a shell script. So, instead, I decided to go the GUI route with a front-end for a tool that is an rsync-like folder, file synchronization tool. It can do much more than we were looking for it to do, but in the end it would do the trick just fine.

In this article I am going to show you how to install and use unison-gtk to merge a pair of local folders on a Linux machine. It will make for a simple example of how this tool can be used for remote folder synchronization, which holds countless uses.

Features

Naturally you will want to know what features unison-gtk offers. Let's take a look:

  • Simple GUI interface for command line tool.
  • Can deal with updates to both replicas of a distributed directory structure.
  • Works well between two network connected machines.
  • Merge the contents of files.

Unison-gtk might not have the most lengthy feature set, but this tool is incredibly handy never the less. Now let's get on with the action.

Installation

Let's install this both using command line and Add/Remove Software. First, command line. To install unison-gtk do the following:

  1. Open up a terminal window.
  2. Issue the command apt-get install unison-gtk (or if you are using a non-sudo type distribution su to root and issue a command like yum install unison-gtk).
  3. Close your terminal when the installation completes.

That's it. Now, let's look at the GUI steps.

  1. Open up the Add/Remove Software utility.
  2. Search for "unison" (no quotes).
  3. Mark both unison and unison-gtk for installation.
  4. Click Apply

That's it. You now have unison-gtk installed. You will find the menu entry in Applications > Accessories.

Usage

Using unison-gtk might seem tricky at first. It's not. You just have to pay close attention to which folders are which. I am going to demonstrate this tool using two folders: TEST and TEST2 (both residing in my users ~/ directory).

Figure 1

When you first fire up unison-gtk it is going to ask you to create a profile. What this profile is really doing is asking you to select the directories you want to sync. You will select the first and then you will select the second. When you come to setting up the second directory you will see (as shown in Figure 1) that you can set this up for remote synchronization via SSH, RSH, or Socket.  You can create more profiles after you have walked through the "first run wizard" as well.  For the sake of this article we are going to stick with local folders.

Figure 2

When your profile is complete unison-gtk will open with your two folders ready (see Figure 2). Pay close attention to how unison-gtk lays out the folders. Both folders are listed in what appears to be a header listing. Where the folders are is important as this will not change. What will change is how unison-gtk indicates what has changed in the folders. Say, when you first fire this up, both folders are in sync. Immediately unison-gtk will check the differences in the folders and let you know what they are. In my current test folders (which have already been sync'd) I have three files: test, test2, test3. Now, let's say I add the file test4 to the TEST directory. When that happens, if I hit the Restart unison-gtk will indicate to me a new file has been found in the TEST directory (see Figure 3).

Figure 3

In order to sync these two folders I have to pay close attention to which way the sync occurs. The way my profile is set up TEST is on the left and TEST2 is on the right. My new file is in TEST so it's on the left. As you would then expect, this sync needs to go LEFT TO RIGHT. Make sure the Action arrow is point in the right direction. If, for example, it were going in the wrong direction unison-gtk would assume you wanted the file erased.

After you are sure the arrow is facing the right direction click the Go button and unsion-gtk will do it's job. You should now have all four files in both TEST and TEST2. Very simple.

Final thoughts

Of course unison-gtk is much more complex than what I have illustrated. But what you have seen here is how easy it can be to merge the contents of two directories on a Linux machine. And in case you are wondering, there is a Windows version of unison-gtk which can be found here.

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:

Comments

  1. Joe said on July 24, 2010 at 5:13 am
    Reply

    Note that the Windows version is command line only, no gtk interface.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.