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.
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
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
diff -qr LHB-1 LHB-2
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
-s, it will show both identical and different files of directories:
diff -qrs LHB-1 LHB-2
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:
- Select the Directory comparison
- Choose directories to compare
- Click on the
Once you click on the compare button, it will show you matching and different files available in the selected directories:
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:
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.