How to Find Difference Between Two Directories Using Diff and Meld Tools

Introduction

Finding the difference between two directories can be a difficult task, especially if the directories contain a large number of files. Fortunately, there are tools available that can help you quickly and easily compare the contents of two directories. The diff and meld tools are two of the most popular tools for this purpose. Diff is a command-line tool that compares two files or directories and displays the differences between them. Meld is a graphical tool that allows you to visually compare two directories and view the differences between them. In this article, we will discuss how to use these tools to find the difference between two directories.

How to Find Difference Between Two Directories Using Diff and Meld Tools

1. Using Diff:

a. Open a terminal window and navigate to the directory containing the two folders you want to compare.

b. Type the following command: diff -r folder1 folder2

c. The output will show the differences between the two folders.

2. Using Meld:

a. Open a terminal window and navigate to the directory containing the two folders you want to compare.

b. Type the following command: meld folder1 folder2

c. The output will show the differences between the two folders in a graphical user interface.

In an earlier article, we reviewed 9 best file comparison and difference (Diff) tools for Linux and in this article, we will describe how to find the difference between two directories in Linux.

Normally, to compare two files in Linux, we use the diff – a simple and original Unix command-line tool that shows you the difference between two computer files; compares files line by line and it is easy to use, comes with pre-installed on most if not all Linux distributions.

The question is how do we get the difference between two directories in Linux? Here, we want to know what files/subdirectories are common in the two directories, those that are present in one directory but not in the other.

The conventional syntax for running diff is as follows:

$ diff [OPTION]… FILES
$ diff options dir1 dir2 

By default, its output is ordered alphabetically by file/subdirectory name as shown in the screenshot below. In this command, the -q switch tells diff to report only when files differ.

$ diff -q directory-1/ directory-2/
Difference Between Two Directories
Difference Between Two Directories

Again diff doesn’t go into the subdirectories, but we can use the -r switch to read the subdirectories as well like this.

$ diff -qr directory-1/ directory-2/ 

Using Meld Visual Diff and Merge Tool

There is a cool graphical option called meld (a visual diff and merge tool for the GNOME Desktop) for those who enjoy using the mouse, you can install it as follows.

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

Once you have installed it, search for “meld” in the Ubuntu Dash or Linux Mint Menu, in Activities Overview on Fedora or CentOS desktop and launch it.

You will see the Meld interface below, where you can choose file or directory comparison as well as a version control view. Click on directory comparison and move to the next interface.

Meld Comparison Tool
Meld Comparison Tool

Select the directories you want to compare, note that you can add a third directory by checking the option “3-way Comparison”.

Select Comparison Directories
Select Comparison Directories

Once you selected the directories, click on “Compare”.

Listing Difference Between Directories
Listing Difference Between Directories

In this article, we described how to find the difference between two directories in Linux. If you know any other command line or gui way don’t forget to share your thoughts to this article via the comment section below.

How to Find Difference Between Two Directories Using Diff and Meld Tools

Finding the difference between two directories can be a difficult task, especially if the directories contain a large number of files. Fortunately, there are a number of tools available that can help you quickly and easily compare the contents of two directories. Two of the most popular tools for this purpose are Diff and Meld.

Using Diff

Diff is a command-line tool that can be used to compare two directories and display the differences between them. To use Diff, open a terminal window and navigate to the directory containing the two directories you want to compare. Then, type the following command:

diff -r directory1 directory2

This will compare the two directories and display a list of the differences between them. The output will look something like this:

Only in directory1: file1
Only in directory2: file2
Common subdirectories: subdir1
diff directory1/file3 directory2/file3
3c3
< line3
---
> line4

The output will show which files are present in one directory but not the other, as well as any differences between files that are present in both directories. In this example, file1 is present in directory1 but not directory2, file2 is present in directory2 but not directory1, and file3 is present in both directories but has some differences.

Using Meld

Meld is a graphical tool that can be used to compare two directories and display the differences between them. To use Meld, open the application and select the “Compare Directories” option. Then, select the two directories you want to compare and click the “Compare” button. Meld will then display a side-by-side comparison of the two directories, showing which files are present in one directory but not the other, as well as any differences between files that are present in both directories.

Using either Diff or Meld, you can quickly and easily compare the contents of two directories and find the differences between them. Both tools are powerful and easy to use, so you should have no trouble finding the differences between two directories.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?