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/

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 [Debian/Ubuntu systems] $ sudo yum install meld [RHEL/CentOS systems] $ sudo dnf install meld [Fedora 22+]
Once you have installed it, search for “meld” in the Ubuntu Dash or Linux Mint Menu, in Activities Overview in 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 version control view. Click on directory comparison and move to the next interface.

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

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

In this article, we described how to find the difference between two directories in Linux. If you know any other commandline or gui way don’t forget to share your thoughts to this article via the comment section below.
I got great value from this post as I currently find myself archiving files onto a backup drive. I installed meld using homebrew on the macOS command line and it worked!
That’s all I needed to do. Thank you so much for the great tutorial. Much appreciated.
Meld is a great tool. Thanks for the recommendation.
@Hugo
Yes, it is, I personally use it a lot. Thanks for the feedback.
There is a great tool called Beyond Compare here
https://www.scootersoftware.com/
.It is a GUI tool with versions for Linux, Mac & Windows. It can also connect to a remote server using sftp.
@Brian
Many thanks for sharing, we will check it out.
Nevermind, we do have a QT version of Meld. It’s called KDiff3
KDE has Kompare but only works for files…
Can i use diff command with remote host , assume second folder on B server than how to use diff command.
@Aashish
You can find difference between two files, one local and another remote, like this:
May be the best tool, in this case, is rsync.