Home Linux Graphical Tools How to Compare Files in Linux Using Meld (Diff/Merge) Tool

How to Compare Files in Linux Using Meld (Diff/Merge) Tool

If you are familiar with diff; a Linux terminal-based tool for comparing two files in terms of contextual differences and layout, you are going to love what Meld has to offer. Think of Meld as a diff tool with graphical upgrades.

Whether you are dealing with Git repository files, directory files, or ordinary system files, the visual capability of Meld makes any file comparing task not only fun but also a walk in the park.

Therefore, sorting through data and code files no longer needs to be a struggle for developers and novice Linux users. Additionally, Meld offers a merge functionality on top of it being a graphical diff tool.

Install Meld in Linux

Before we can learn the ropes of implementing Meld as an effective file comparison tool, we first need to have it installed and running on our Linux system.

Depending on your Linux system distribution preference, install Meld in reference to the following installation command options. Ensure you are a Sudoer user or you have Sudo privileges on the Linux system you are using.

$ sudo apt-get install meld     [On Debian, Ubuntu and Mint]
$ sudo yum install meld         [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a sys-apps/meld  [On Gentoo Linux]
$ sudo pacman -S meld           [On Arch Linux]
$ sudo zypper install meld      [On OpenSUSE]    

Comparing Two Files in Linux Using Meld

Create two files with slightly different content structures. We will be using these files to demonstrate the power of Meld as a file comparing tool.

Create the first file.

$ nano file1

We will populate this file with some random content.

1 2 3 4 5 6 7 8 9 10
one two three four five six seven eight nine ten
This file contains some number sequences in numeric and textual form.
Regards,
LinuxShellTips Tutor

Create a second file.

$ nano file2

and again populate it with the following content.

11 2 13 4 15 6 7 8 19 10
one twice three four five six seven eight nine ten
This file contains some number sequences in numeric form and some textual representation of the numbers.
Regards,
LinuxShellTips Tutor

Comparing Two Files in Linux

We can now implement and execute a file comparison attempt regarding these two files.

$ meld file1 file2
Comparing Two Files Using Meld
Comparing Two Files Using Meld

Firstly, Meld highlights the portion of both files that are different from the light blue foreground color. It then uses a dark blue foreground color to point out key contextual elements that make these two files dissimilar.

Comparing Three Files in Linux

Unlike the diff file comparing tool, Meld’s file comparing capability can flexibly extend to three files. Let us create a third file and make it slightly different than the first two files we compared.

$ nano file3

Add the following content to it.

21 22 23 24 25 26 27 8 9 10
ones twice thrice fourth fifth sixth seventh eight nine ten
This file contains some number sequences in numeric and textual formats.
Regards,
LinuxShellTips Tutor

Let us now try to compare file1, file2, and file3 at the same time.

$ meld file1 file2 file3
Compare There Files in Linux
Compare There Files in Linux

As expected, Meld has highlighted the portion of the three files that are different and left out the contextual portion that is identical in all files.

Editing Compared Files in Linux

Whether you use Meld to compare file changes on two or three files, sometimes you may want to do more than just note the differences between these files. Meld opens your files in an editable editor environment.

To edit your files, you need to execute Meld.

$ meld file1 file2
Edit Compare Files in Linux
Edit Compare Files in Linux

In the above case, we have successfully edited both files and saved the changes through Meld.

Comparing Two Directories in Linux

We can also stretch our luck with Meld and compare two directories if needed. Use root privileges to run this command for effectiveness.

$ meld Documents Downloads
Compare Two Directories in Linux
Compare Two Directories in Linux

When using Meld to handle directory files, Four important Meld features stand out:

Meld Compare

This feature highlights the main differences between the two files.

Compare Files in Linux
Compare Files in Linux
Meld Same

This feature will try to fetch similar files between the two directories.

Fetch Files Between Two Directories in Linux
Fetch Files Between Two Directories in Linux
Meld New

This feature sorts out and displays new directory file additions between the two directories under comparison.

List Files Difference Between Two Directories
List Files Difference Between Two Directories
Meld Modified

If you have a recently modified directory file you would like to take note of, this Meld feature takes care of such needs.

List Modified Files Between Two Directories
List Modified Files Between Two Directories

Meld’s visualization makes it an ideal file and directory comparing tool as it easily deciphers the tiniest of differences between targeted files and directories. Also, if you are a developer addicted to Git, Meld is perfect for comparing your commits before you can push or pull any code changes to your repositories.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

2 thoughts on “How to Compare Files in Linux Using Meld (Diff/Merge) Tool”

  1. There is no need to use sudo, except for administrative tasks like installing packages.

    Moreover especially graphical tools shouldn’t be called with admin privileges.

    Please refrain from publishing this level of knowledge.

    Reply

Leave a Reply to Heiko Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.