June 27, 2008

Synchronize directories with Komparator and KDiff3

Author: Federico Kereki

If you work some of the time on your laptop and some of the time on your desktop box, making sure that your work is updated on both machines is a must. Many tools can help you accomplish this, from command-line tools such as scp and rsync to generic graphical applications like Konqueror or Krusader, to more specific tools like Unison. Komparator and KDiff3, a couple of KDE applications with interesting features, may offer better ways of syncing your work.

Komparator can search and synchronize any two directories. It uses KIO slaves, which lets you compare not only standard directories, but also protocol-based pseudofolders such as smb:// (Samba folders), ssh:// and ftp:// (remote directories via SSH and FTP), and fonts:// (local fonts). Its latest version is 0.8, dated from October 2007, and it's available under the GPLv2.

Installation is fairly easy. You can either opt for a source download or take advantage of Ubuntu or SUSE-specific versions at the download site. I downloaded the openSUSE 10.3 version and installed it with sudo rpm -Uvh komparator-0.8-SuSE_10.3.i586.rpm. An entry was added to the main menu under Utilities -> Archiving. If you're running other distributions, you'll have to get the source package, extract it, and install it with the classic configure, make, make install method.


Documentation isn't extensive. When running the program, clicking on the Help button in the lower-right corner takes you to the Komparator Handbook, and that's it. Also, the program is available only in English, so international users may be out of luck.

Komparator's main window is crowded and doesn't follow any but the most basic interface standards. Having About and Help as command buttons, or duplicating the "What's this" functionality with a button of its own, isn't usual, to say the least. You need to pick two directories and specify which files should be synchronized through Basic Search Options and Extended Search Options. You can do a recursive process ("include subfolders"), include hidden files, treat file names as case-sensitive (why wouldn't you in a Linux/Unix system?), and more. Komparator can also find duplicate files either by doing a byte-per-byte comparison or by calculating an MD5 checksum for the files; if the checksums match, it assumes the files are the same.

Before you begin, check the Settings tab and pick what things you want to do. Then select the URLs you want to sync; note that the "left" URL is the one on top, and the "right" URL is the one at the bottom. Finally, click on Search, and you'll get the results of the comparison:

  • Duplicate files shows you files that are found more than once. This has nothing to do with the goal of synchronizing directories, but it can be useful.
  • Missing files shows you the files that are at one URL but not the other. Komparator can copy these to get directories in sync.
  • Newer files shows you all the files in a not-too-clear color scheme. If you pick a left file and the corresponding right file, you can right-click to get a comparison of the file statistics, such as size, type, and owner. However, you can't see the file contents.

To finish the process, select the files you would like to copy, move, or delete, and use the six buttons that are displayed between the two directories to synchronize everything. The buttons allow you to copy or move from right to left or from left to right, and to delete files from each side. This can be a chore for large directories; a single "do everything" button would be a nice addition.



KDiff3 provides more functions than Komparator, but not all are relevant to synchronization. Working with directories, KDiff3 goes further than Komparator -- it can compare as many as three directories at the same time (instead of two), simulate the merge operations, do the synchronization in a more "hands-off" way, and even produce backups. More importantly, it can also help you compare specific files (think source files, if you're a programmer) by highlighting their differences, then merging them. In KDiff3, a merge need not be simply one file overwriting another. If you've ever modified a file on one machine and then carelessly made another change to a copy of the file on a different machine, common merging procedures would opt for one of the files, making you lose the changes on the other one. With KDiff3, you could get to keep both changes.

The latest version of this program is 0.9.92 from April 2007. Since it was written using Trolltech's Qt, it can also run under Windows and Mac OS X. The program has been "internationalized" into several languages, and unlike Komparator, sports good documentation, which is also available as PDF files. A KDiff3 Handbook is available from the program's Help menu.

You can find KDiff3 in the standard openSUSE software repositories. I simply had to enter smart install kdiff3 and I was on my way. (A somewhat quirky point: the program installed itself in the menu under Development -> Revision Control, which makes sense for programmers, but not for common users, who would think about it as a filesystem application or utility.) For other distributions, get the source package file, extract it with tar xzf kdiff3-0.9.92.tar.gz, change to the created directory, and install the software the "configure, make, make install" way.

KDiff3 integrates itself with the desktop and Konqueror, and you can select two files or directories, right-click, and compare them. However, on my desktop box, doing that made my X session crash consistently, forcing me to log in again. If both files aren't at the same location, you have another option: right-click on the first file, click "Save it for later," and then right-click on the second file to do the actual comparison. However, that also produced the crash on my desktop system. KDiff3 performs flawlessly on my laptop, however.

Opening KDiff3 pops up a window where you can enter the two (or three) directories to be compared. You should also check the Configuration screen, and the Directory Merge tab specifically. At the very least, check Recursive Directories if you want to include subdirectories in the comparison, enter file patterns to show what files to include or avoid, and set the file-comparison mode (from binary, meaning the files are compared on a byte-per-byte basis, to "trust size," which just checks whether the file sizes differ). Finally, select Synchronize Directories (why isn't this option checked by default?) so the directories will end up with the same contents after all comparisons.

The results of the comparison are shown in a single display, with columns (A, B, and C) marking which files are in which directory. At the upper right, three graphic checkboxes allow you to hide files that are the same (so you can concentrate on different files) or just show the new files on one of the directories. The Operation column shows you what needs be done to synchronize files. If you click on any file marked "Merge (manual)," you will get a line-by-line comparison of both files, showing which lines were added, deleted, or modified. It's up to you to do the merging or to decide which file should be the good one. (The Diffview menu entry allows you to configure the comparison view.) If you right-click on the Operation column, you get an easy way to decide which operation should be done. When you're done selecting what is to be done, use the Directory menu entry to confirm your choices.


Though both programs do their job, they're not without some nuisances. Komparator's quirky interface is too crowded, and it lacks a simple way of getting things done without a lot of clicks. KDiff3 seems better oriented to comparing text files, but it requires a lot of intervention by the user. Both seem oriented to developers and can be overwhelming for common users, who would be better served by Krusader's synchronizing tool. For programmers, though, KDiff3 is probably the better option.


  • Reviews
  • Tools & Utilities
  • System Administration
Click Here!