Home  >  Article  >  System Tutorial  >  Use the Diff and Meld tools to compare the differences between two directories

Use the Diff and Meld tools to compare the differences between two directories

WBOY
WBOYOriginal
2024-08-21 16:39:30463browse

Generally, to compare two files under Linux, we will use diff (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 -q switch is telling #🎜🎜 #diif Only report if files have differences.

$ diff -q directory-1/ directory-2/

使用 Diff 和 Meld 工具比较两个目录的不同处

Difference between two folders

Running

diff again does not allow us to enter the subfolder, but we can use the -r switch to read the subfolder, as shown below.

$ diff -qr directory-1/ directory-2/ 
Use Meld visual comparison and merging tool

meld is 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+]
Once you have it installed, search for "

meld" in Ubuntu Dash or 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.

使用 Diff 和 Meld 工具比较两个目录的不同处

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.

使用 Diff 和 Meld 工具比较两个目录的不同处

Select the folder to compare

After selecting the folders to compare, click “Compare”.

使用 Diff 和 Meld 工具比较两个目录的不同处

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn