Skip to main content

Compare Two Directories in the Linux Command Line

Want to see how the content of the two directories differs? Use the diff command and see what files are identical or different.

Sagar Sharma

Warp Terminal

How do you compare two files in Linux? You use the diff command.

But how do you compare two folders in Linux? You still use the diff command.

It is easier to visualize the difference between two directories using a GUI tool.

In this tutorial, I'll share how you can use the diff command to compare directories. I will also discuss a GUI tool called Meld.

The tree command shows the structures of the two directories I use in the examples.

setup for comparing two directories in Linux

So let's start this tutorial with the CLI method.

Use the diff command to compare directories in Linux

To use the diff command, you will have to follow a simple syntax:

diff -qr Directory-1 Directory-2

To find the differences, you will have to use the -q option which will report only when the difference is found.

diff -q LHB-1 LHB-2
compare two directories in linux

But if you notice carefully, the diff command only looked on file level 1. By default, it won't look for the files inside the subdirectory.

To perform the search including the subdirectory, you will have to use the -r flag:

diff -qr LHB-1 LHB-2
compare directories recursively in linux

But what if you want to know the similar files too?

You can easily do that using the -s flag. So if you will use both flags -q and -s, it will show both identical and different files of directories:

diff -qrs LHB-1 LHB-2
find identical and different files of multiple directories in linux
The diff command shows what files differ in the directories. To see the difference, you can run the diff command again on the files to see how their content differs.

Use GUI to compare directories in Linux

If you are not a terminal fan and want to compare the directories in the easiest way possible, use Meld.

Meld is a GUI tool that allows you to check and merge differences.

You'll have to install it first. In Ubuntu/Debian, use:

sudo apt install meld

It is also available as a flatpak:

flatpak install flathub org.gnome.meld

If you haven't configured flatpak on your system, check out our detailed guide on how to set up flatpak on various Linux distros.

Once you are done with the installation, open the Meld from your system menu and follow the three easy steps:

  1. Select the Directory comparison
  2. Choose directories to compare
  3. Click on the Compare button
select directories to compare on meld

Once you click on the compare button, it will show you matching and different files available in the selected directories:

compare directories using meld

The ones which are marked with stars are the exact match.

Whereas filenames highlighted with green are only available to that respective directory.

Looking for more tools to compare?

If you are looking for more tools to compare files with various features, we already have a dedicated guide for that:

Compare Files in Linux With These Tools
Whether you’re a programmer, creative professional, or someone who just wants to browse the web, there are times when you find yourself finding the differences between files. There are two main tools that you can use for comparing files in Linux: * diff: A command line utility that comes…

And if you have any queries related to this guide or want to suggest me what should I cover next, let me know in the comments.  

Sagar Sharma