> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Compare Two Directories in the Linux Command Line
- URL: https://linuxhandbook.com/compare-directories/
- Published: 2023-01-16T05:40:35.000Z
- Updated: 2023-01-16T05:40:35.000Z
- Description: Want to see how the content of the two directories differs? Use the diff command and see what files are identical or different.
- Author: Sagar Sharma
- Tags: Tips

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](https://linuxhandbook.com/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](https://linuxhandbook.com/tree-command/) shows the structures of the two directories I use in the examples.

![setup for comparing two directories in Linux](https://linuxhandbook.com/content/images/2023/01/setup-for-comparing-two-directories-in-Linux-1.png)

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](https://linuxhandbook.com/content/images/2023/01/compare-two-directories-in-linux.png)

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](https://linuxhandbook.com/content/images/2023/01/compare-directories-recursively-in-linux.png)

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](https://linuxhandbook.com/content/images/2023/01/find-identical-and-different-files-of-multiple-directories-in-linux.png)

💡

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](https://meldmerge.org/?ref=linuxhandbook.com) 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.](https://itsfoss.com/flatpak-guide/?ref=linuxhandbook.com)

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](https://linuxhandbook.com/content/images/2023/01/select-directories-to-compare-on-meld.png)

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

![compare directories using meld](https://linuxhandbook.com/content/images/2023/01/compare-directories-using-meld.png)

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 ToolsWhether 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…![](https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png)It's FOSSSagar Sharma![](https://itsfoss.com/content/images/wordpress/2022/08/gui-and-cli-tools-for-comparing-files.jpg)](https://itsfoss.com/compare-files-linux-tools/?ref=linuxhandbook.com)

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.