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
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
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
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
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.
Meld Same
This feature will try to fetch similar files between the two directories.
Meld New
This feature sorts out and displays new directory file additions between the two directories under comparison.
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.
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.
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.
@Heiko,
Thanks for the input, I have corrected the article as suggested by you…