使用 Meld 在 Linux 中以图形方式比较文件和文件夹
diff 比较
![](/data/attachment/album/202011/28/145914mr5zcl2wnns8rj5j.jpg)


如何比较两个相似的文件来检查差异？答案显而易见，就是[使用 Linux 中的 diff 命令](https://linuxhandbook.com/diff-command/)。


问题是，并不是每个人都能自如地在 Linux 终端中比较文件，而且 `diff` 命令的输出可能会让一些人感到困惑。


以这个 `diff` 命令的输出为例：


![](/data/attachment/album/202011/28/150137anmhkwoqpqd2cfnc.png)


这里肯定涉及到一个学习曲线。然而，如果你使用的是桌面 Linux，你可以使用 [GUI](https://itsfoss.com/gui-cli-tui/) 应用来轻松比较两个文件是否有任何差异。


有几个 Linux 中的 GUI 差异比较工具。我将在本周的 Linux 应用亮点中重点介绍我最喜欢的工具 Meld。


### Meld：Linux（及 Windows）下的可视化比较和合并工具


通过 [Meld](https://meldmerge.org)，你可以将两个文件并排比较。不仅如此，你还可以对文件进行相应的修改。这是你在大多数情况下想做的事情，对吗？


![File Comparison](/data/attachment/album/202011/28/145956hp3qpa52ypudtw95.png)


Meld 还能够比较目录，并显示哪些文件是不同的。它还会显示而文件是新的或是缺失的。


![Directory Comparison](/data/attachment/album/202011/28/150003ovv6gs6iwyzzygsd.png)


你也可以使用 Meld 进行三向比较。


![Three Way File Comparison](/data/attachment/album/202011/28/150010saxeegieehleo2cm.png)


图形化的并排比较在很多情况下都有帮助。如果你是开发人员，你可以用它来了解代码补丁。Meld 还支持版本控制系统，如 Git、[Mercurial](https://www.mercurial-scm.org/)、[Subversion](https://subversion.apache.org/) 等。


### Meld 的功能


![](/data/attachment/album/202011/28/150014rj3vhvl9vijhmj9i.png)


开源的 Meld 工具具有以下主要功能：


* 进行双向和三向差异比较
* 就地编辑文件，差异比较立即更新
* 在差异和冲突之间进行导航
* 通过插入、更改和冲突相应地标示出全局和局部差异，使其可视化
* 使用正则文本过滤来忽略某些差异
* 语法高亮显示
* 比较两个或三个目录，看是否有新增加、缺失和更改的文件
* 将一些文件排除在比较之外
* 支持流行的版本控制系统，如 Git、Mercurial、Bazaar 和 SVN
* 支持多种国际语言
* 开源 GPL v2 许可证
* 既可用于 Linux，也可用于 Windows


### 在 Linux 上安装 Meld


Meld 是一个流行的应用程序，它在大多数 Linux 发行版的官方仓库中都有。


检查你的发行版的软件中心，看看 Meld 是否可用。


![Meld In Ubuntu Software Center](/data/attachment/album/202011/28/150023psh63wgsrgug1ue2.png)


另外，你也可以使用你的发行版的命令行包管理器来安装 Meld。在 [Ubuntu 上，它可以在 Universe 仓库中找到](https://itsfoss.com/ubuntu-repositories/)，并且可以[使用 apt 命令安装](https://itsfoss.com/apt-command-guide/)：



```
sudo apt install meld

```

你可以在 GNOME 的 GitLab 仓库中找到 Meld 的源码：


[Meld Source Code](https://gitlab.gnome.org/GNOME/meld)


### 它值得使用吗？


我知道[大多数现代开源编辑器](https://itsfoss.com/best-modern-open-source-code-editors-for-linux/)都有这个功能，但有时你只是想要一个简单的界面，而不需要安装额外的附加软件来比较文件。Meld 就为你提供了这样的功能。


你是否使用一些其他工具来检查文件之间的差异？是哪种工具呢？如果你用过 Meld，你有什么经验？请在评论区分享你的意见。




---


via: <https://itsfoss.com/meld-gui-diff/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
How do you compare two similar files to check for differences? The obvious answer is [to use the diff command in Linux](https://linuxhandbook.com/diff-command/).

The problem is that not everyone would be comfortable comparing files in Linux terminal. And the diff command output could be confusing for some.

Take this diff command output for example:

![Diff Command Complicated Output](https://itsfoss.com/content/images/wordpress/2020/11/diff-command-complicated-output.png)

There is definitely a learning curve involved here. However, if you are using desktop Linux, you can use [GUI](https://itsfoss.com/gui-cli-tui/) applications to easily compare two files for any differences.

There are several GUI diff [tools available for Linux to compare files](https://itsfoss.com/compare-files-linux-tools/). I am going to highlight my favorite tool Meld in this week’s Linux application highlight.

## Meld: Visual Diff and Merge tool for Linux (and Windows)

With [Meld](https://meldmerge.org), you can compare two files in side by side view. Not only that, you may also modify the files to make changes accordingly. That’s what you would want to do in most situations, right?

![File Comparison In Linux With Meld](https://itsfoss.com/content/images/wordpress/2020/11/file-comaprison-in-Linux-with-meld-800x498.png)

Meld is also capable of comparing directories and show which files are different. It will also show while files are new or missing.

![Directory Comparison In Linux With Meld](https://itsfoss.com/content/images/wordpress/2020/11/directory-comparison-in-Linux-with_meld-800x497.png)

You may also use Meld for a three-way comparison.

![Three Way File Comparison With Meld In Linux](https://itsfoss.com/content/images/wordpress/2020/11/three-way-file-comaprison-with-meld-in-linux-800x466.png)

The graphical side-by-side comparison helps in a number of situations. If you are a developer, you can use it to understand code patches. Meld also supports version control systems like Git, [Mercurial](https://www.mercurial-scm.org/), [Subversion](https://subversion.apache.org/) etc.

## Features of Meld

![Meld Visual Diff in Linux](https://itsfoss.com/content/images/wordpress/2020/11/meld-visual-diff.png)

The open source Meld tools has the following main features:

- Perform two and three-way difference comparison
- Edit files in-place and the difference comparison updates immediately
- Navigate between differences and conflicts
- Visualize global and local differences with insertions, changes and conflicts marked accordingly
- Use regex text filtering to ignore certain differences
- Syntax highlighting
- Compare two or three directories for newly added, missing and altered files
- Exclude some files from comparison
- Support for popular version control systems like Git, Mercurial, Bazaar and SVN
- Support for many international languages
- Open source GPL v2 license
- Available for Linux as well as Windows

## Installing Meld on Linux

Meld is a popular application and it is available in the official repositories of most Linux distributions.

Check your distribution’s software center and see if Meld is available.

![Meld In Ubuntu Software Center](https://itsfoss.com/content/images/wordpress/2020/11/Meld-in-Ubuntu-Software-Center-800x384.png)

Alternatively, you can also use command line package manager of your distribution to install Meld. On [Ubuntu, it is available in the Universe repository](https://itsfoss.com/ubuntu-repositories/) and can be [installed using the apt command](https://itsfoss.com/apt-command-guide/):

`sudo apt install meld`


You may find the source code of Meld on GNOME’s GitLab repository:

## Worth it?

I know that [most modern open source code editors](https://itsfoss.com/best-modern-open-source-code-editors-for-linux/) come with this feature but sometimes you just want a simple interface without the trouble of installing additional add-ons for comparing files. Meld provides you just that.

Do you use some other tools for checking differences between files? Which tool would that be? What’s your experience with Meld, if you ever used it? The comment sections is all yours for sharing your opinion.