Comparing files and folders with `meld`

We have all used diff or cmp to compare two files
cmp is silent … it only tells you if there is a difference
diff has a horrendous output intended to be computer readable, and it suffers from the issue of one extra line lleading to every subsequent pair of lines being flaggd as different.

There is a better way. meld is like diff with a gui. It can compare

  • 2 or 3 files
  • 2 or 3 folders
  • a file with its copy in a git repository
    You can install meld as a package from Debian repository, ie
apt install meld

is all that is required.

`Meld has a startup entry in the Applications Menu. It is in the Development section. Alternatively you can start it from the command line

meld
or
meld file1 file2
there are other options see later

If you start meld without a filename you get


A rather plain window.
If you click on File you can enter 2 filenames and when you hit Compare you get

You see 2 versions of a file ( xvpng.c) in different directories.
One has some extra #include statements.

You can also compare 2 Folders. Click on Folders and enter 2 folder names , click compare and you get


There you can see the missing files in the right hand folder are struck out

Lastly, if you use git, you can compare one file with its copy in the git repository


You can see the and the actual file on the right.
I have not yet committed some changes to git.

`Meld can also do other things, such as merge files.
Here is the start of its man page

Meld is not solely for programmers. You can compare any text files, eg data files, documents.

Give it a try. It works for me.

9 Likes

It looks quite a bit like WinMerge for Windows. I use that quite a bit at work. As far as I know it doesn’t have any git capabilities. Maybe it would run under wine. It is open source.

WinMerge - You will see the difference…

3 Likes

@nevj :

Hi Neville, :wave:

just read your post.
meld seems to be a great tool. By the looks of it I already like it a lot.

Until now I always used diff -s to see whether two files are identical.
simple diff (when files are different) can lead to an immensely long output, as you already pointed out.

I´ll certainly give meld a try. I like the fact that it´s usbale for comparing folders as well. :+1:

Thanks for the tip, Neville.

Many greetings from Rosika :slightly_smiling_face:

3 Likes

Yes, meld is open source, GPL licence.
It does indeed look like WinMerge. You should feel at home .

3 Likes

Hi Neville,
Thank you very much for spreading the word about meld.
Like pdecker, I used to use winmerge on Windows, but I hadn’t yet found a similar program for Linux.
I’ll have to try it out.

Jorge

2 Likes

@nevj :

Hi Neville, :wave:

I just installed meld after having had a look at its a standalone binary.
First I tried this:

git clone https://github.com/GNOME/meld.git
cd meld
firejail --profile=/etc/firejail/meld.profile ./bin/meld

… which at first went well. But I couldn´t get it to run within firejail.

So I installed it, like you suggested in your first post.

The installed version works better within the sandbox, but:

Let´s say I want to load the file /home/rosika/.config/firejail/meld.profile (just as an example). It first seems to get loaded but an error mesage pops up:

There was a problem opening the file “/home/rosika/.config/firejail/meld
Error opening file /home/rosika/.config/firejail/meld.profile: Permission denied

I already discussed it with glitsj16 here:

The explanation of it is this:

Firejail hardcodes some paths as inaccessable by default for security reasons.

Pretty sure ~/.config/firejail is one of those. I can see how this would be awkward for a diff tool like meld, but perhaps you can temporarily move whatever you need to diff out of ~/.config/firejail into ~/Downloads for example.
The latter (or a subdir) should pose no access problems for meld.

Just as an iformation for anyone wanting to run meld within firejail.

Many greetings from Rosika :slightly_smiling_face:

3 Likes

Thanks @nevj

Another tool I did not know about. This will come in handy in comparing document folders from individual machines and the nfs-server as I did not want to duplicate items.

Sheila

4 Likes

Hi @all:

for anyone interested, I´ve written a script for running meld within the firejail sandbox.
It´s for coparing 2 files.

… it can be found here:

Many greetings from Rosika :slightly_smiling_face:

4 Likes

Meld is a nice option. I often prefer command line tools. diff can be hard to read, but very useful. I looked at several file comparison tools years ago. I found diffh at Sourceforge. It’s a nice program to use with diff to make output more readable similar to programs like meld and winmerge. diffh is a command line program. It creates output you can view in your favorite browser. I use diff with diffh to add file comparison functionality to my programming editor. It’s a nice cross-platform solution that can run on most operating systems. It’s barebones, but it does everything I need for file comparison.

3 Likes

I like that.
Does it avoid the diff problem of one extra line in one file leading to many mismatches?
That is what I like about meld, it avoids that.

1 Like

It takes the diff output and reformats it to make it more readable. So, it’s only as good as diff is. Have you tried the BSD diff versus the GNU diff. They use different algorithms for line matching.

1 Like

Never noticed that. Will have a closer look. Thank you.

1 Like