Linux GUI diff utilities a visual tour

Posted February 27th, 2009 by mr-Z

showing differences in files

If you edit a lot of configuration files, and are confronted a lot with the configuration files edited by others, you probably spend a lot of time looking at the changes made to the file since the last time it was edited or installed. The standard command line utility diff does a reasonable job when it comes to finding small differences. It shows that it wasn't developed to create the best possible human readable output when you try reading long listings.

diff output looks something like this:

2c2
<
---
> text in file 1
12,14d11
< text in file 2
< which is not
< in file 1

great for changing code with patch, a little less great for editing text by hand.

If you just need a quick and dirty side by side view of a small piece of text, sdiff is your tool.
Output of sdiff is like this:

test text, to show differences with sdifftest                 text, to show differences with sdiff
test                                                          <
text                                                            text
to                                                            | test
                                                              > toto
show differences sdiff shows                                    show differences sdiff shows

Luckily there are a lot of possible choices for more advanced diff utilities:

vimdiff

If you need to stick with the command-line there's vimdiff, vimdiff is a startup option of vim. And if your used to the vi commands this is a great file comparison option. Vimdiff is started by entering

#vimdiff file1 file2

on the command line. You can open a number of files in a split view this way. It's also possible to start the diff mode when you're already in the editor. If you have a file opened in vim and you do give the command
:diffsplit {filename}

click on the screenshots for larger images:

unfolding in vimdiff is done by putting your cursor on the fold and pressing the keys z-o
fold it again with z-c
remember this by thinking of the z as a folded line and o is open / c is close.
vimdiff supports syntax coloring, code folding, multiple buffers, well all standard vim features. The only thing is that you have to know vi commands to work with it. While there's always a good reason to learn vi
(it boosts your productivity),you might be more interested in other tools if you are not used to the vi editing style yet.

gvimdiff

There's also gvim this is a gui version of vi which sports a file menu and other gui options. And so there's also gvimdiff, which is a gui version of vimdiff. Gvimdiff can be started from the command line just like vimdiff by entering

#gvimdiff file1 file2

gvim is a great tool in itself and if you need to learn vi it helps you a lot by giving lists of commands and other helpful info.
In gvim you can open multiple files in split screens, this is normal mode. You can also start a diff from the menu file--split diff with, this gives you a split screen with all settings like in vimdiff. Code is folded where it's not different, just unfold by clicking the + in the sideline.

Gvim is a vi bases editor and therefore it has a editing and command mode. To enter edit mode you enter one of the edit keys and to re-enter command mode you use esc. Working with vi based editors takes some getting used to, this is as well a weak point as a strong point of this program. If your used to vi or vim, your definitely going to like this one. In other cases it's something you need to learn and if you're in a hurry you'dd better try one of the other tools.

click on the screenshots for larger images:

Emacs

Emacs has similar features and a command line and GUI mode also.
When in emacs press Meta-x followed by ediff-files, and you'll be asked for the filenames which you want to compare.

emacs supports a lot of diff commands for a full list and the manual go here:

ediff manual

click on the screenshots for larger images:

If your used to emacs text editing the ediff function is probably your choice when comparing files, emacs has great support for comparing files. It compares to vi in productivity and speed if your used to it.
If you don't know it's command structure and don't have time to learn, you're probably better off with one of the GUI only text comparing tools.

The GUI file differencing tools can roughly be divided into the ones which let you edit in place and the ones that don't. I personally like to have the ability of editing the files I'm looking at, but for a quick compare of 2 files many of this tools come in hand. It's all a matter of personal preference.

Kompare

Kompare has a clear interface where you see differences between files and you have the ability to apply the differences to the target file. A lightweight application which doesn't allow for editing in the windows.
Kompare has several different options for ignoring whitespace (tabs, spaces, blank lines,tab expansion)
It has an ignore case option and options for regular expression match ignoring.
Excluding files is an option in directory comparison.
The external diff program can be set and there's color configuration available.
That's pretty much it. Kompare is a relatively simple tool, but if that's just what you need it serves it's purpose well.

click on the screenshots for larger images:

edit: there's a second page!
page2 --->


diff ftw

Anonymous 1 year 11 weeks 5 days 7 hours ago

I was always a fan of just using plan old diff and outputting it to a patch file, either that or SVN! Let that sit for a while and think about it :)

Beyond Compare blows all these out of the water!

Anonymous 1 year 21 weeks 3 days 20 hours ago

I still can't believe that people don't know about Beyond Compare. It is "THE" compare program to use. It is by no means free, but it is professional grade, and nothing comes close to it. And NO i don't work for them, I have just been using it for 5+ years on the windows platform and I am very happy that they've finally got a port for Linux! Give it a try and you'll see for your self that this is the only way to compare files AND folders.

edit:link removed, it's on page 2

Sourcegear's Diffmerge

Anonymous 1 year 26 weeks 15 hours 26 min ago

http://www.sourcegear.com/diffmerge/ is available for Linux, Mac, and Windows. It's free-as-in-beer, but not open source.

I like xxdiff

Anonymous 1 year 26 weeks 2 days 18 hours ago

If you need to go GUI, use xxdiff!

http://furius.ca/xxdiff/

Other diff apps.

Anonymous 1 year 26 weeks 3 days 6 hours ago

I normally use kdiff3 which a few others have previously mentioned.

The other utility I sometimes use is tkdiff:
I recently needed to put a visual diff app on my eeePC 701. I wanted kdiff3 but gave up after repository difficulties. Thus I used tkdiff, a visual diff utility written in tcl/tk. This language allowed me to create a single-file executable (a starpack) and simply copy it to the eeePC - no dependency or other problems...

Diffuse is also extremely portable

Anonymous 1 year 26 weeks 1 day 19 hours ago

Diffuse is also very portable. It just needs Python and PyGTK which are present on practically every Linux distribution. All of the support files are completely optional. Just copy /usr/bin/diffuse to another machine and use it.

what about kdiff3 ?

Anonymous 1 year 26 weeks 5 days 45 min ago

what about kdiff3 ?

Other possibilities...

Anonymous 1 year 26 weeks 5 days 51 min ago

I would recommend checking out meld, http://meld.sourceforge.net/, and jedit's jdiff plugin.

for meld see the next comment

admin 1 year 26 weeks 4 days 23 hours ago

meld is on page 2, see the next comment.
I'll look into jdiff and add it as soon as I find the time.

Where's meld ? And kdiff3 ?

Anonymous 1 year 26 weeks 5 days 53 min ago

Where's meld ? And kdiff3 ?

meld

admin 1 year 26 weeks 4 days 23 hours ago

for meld check out page 2!

there's a link at the bottom page2 --->

or direct:

http://www.handlewithlinux.com/Linux-GUI-diff-utilities-a-visual-tour-page2

I'll be adding kdiff3 as soon as I find the time

I've updated the text to make the link to the second page a "little" clearer :-)