Open In App

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

Last Updated : 07 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The diff is a straightforward, original Unix command-line utility that displays the differences between two computer files. It compares files line by line, is simple to use, and is preinstalled on the majority, if not all, Linux distributions. How can we determine the differences between two folders in Linux is the query. Here, we’re interested in discovering which files/subdirectories shared by the two directories, or those that exist in one directory but not the other, are. 

For those who prefer using the mouse, there is a fantastic graphical solution called meld (a visual diff and merge application for the GNOME Desktop), which you can install using the steps below. 

Method 1: Using the diff command

Basic Syntax:

The general syntax of the diff command is as follows

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

Example:

In the below example, we will find the difference between the Two Directories

Step 1: List the files of directory1.

cd directory1
ls

 

Step 2: List the files of directory2.

cd directory2
ls

 

Step 3: Finding the difference between directory1 and directory2

diff -q directory1/ directory2/

We have got the results that state the common file and sub-directories between directory1 and directory2.

 

Step 4: Recursively read the sub-directories as well by using the -r flag.

diff -qr directory1/ directory2/ 

The below results state the common files and directories in sub-directories of directory1 and directory2.

 

Method 1: Using Meld Visual Diff and Merge Tool

Step 1: Install the Meld GUI tool using the below command

sudo apt install meld

 

Step 2: Click on OK for proceeding with the installation.

 

Step 3: To open the application, click on Activities Panel and search for the Meld tool.

 

Step 4: Click on the Meld tool icon to open for usage.

 

Step 5: Select the New Folder Option. Select the directories which you want to compare. Here we have selected directory1 and directory2.

 

Step 6: We have got the difference between the two directories and also their sub-directories. 

 

So, in this article, we described the difference between the two directories using 2 possible methods. 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads