Generally, to compare two files under Linux, we will usediff(a simple command line tool derived from Unix) to display the differences between two computer files; It compares files line by line and is very easy to use. It is pre-installed in almost all Linux distributions.
The question is how can we compare two directories under Linux? Now, we want to know which files/subdirectories are common to both directories and which ones only exist in one directory.
The general syntax for running diff is as follows:
$ diff [OPTION]… FILES $ diff options dir1 dir2
By default, the output is sorted alphabetically by the file name of the file/subfolder, as shown in the screenshot below, in the command, the-qswitch is telling # #diifOnly report if files have differences.
$ diff -q directory-1/ directory-2/
Difference between two folders
Runningdiffagain does not allow us to enter the subfolder, but we can use the-rswitch to read the subfolder, as shown below.
$ diff -qr directory-1/ directory-2/
meldis a cool graphical tool (a visual comparison and merge tool under the GNOME desktop) for those who like to use 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+]
meld" inUbuntu Dashor the Linux Mint menu, or the Activities Overview of the Fedora or CentOS desktop, and launch it.
You can see the following Meld interface, where you can select files or folders to compare, and there is also a version control view. Click Directory Compare and move to the next interface.Meld comparison tool
Select the folder you want to compare. Note that you can check the "3-way Comparison" option to add a third folder.
Select the folder to compare
After selecting the folders to compare, click “Compare”.Different list of folders
In this article, we describe how to find the difference between two folders in Linux. If you know of other commands or GUI tools, don’t forget to share your thoughts in the comments below.The above is the detailed content of Use the Diff and Meld tools to compare the differences between two directories. For more information, please follow other related articles on the PHP Chinese website!