# 在Linux中并排显示文件

## 使用diff命令

diff命令是一个标准的Linux工具，用于比较两个文件并显示它们之间的差异。它可以使用”-y “或”-side-by-side “标志来并排查看文件。

$diff file1 file2 4,5c4,5 < This is the fourth line in file < This is the fifth line in file --- > This is the fourth line in filex > This is the fifth line in filex  #### 要并排查看文件，使用”-y “标志 输出将显示两个文件之间的差异，文件中的每一行都会并排显示。任何不同的行将以红色突出显示。 下面是一个使用diff命令来比较两个文件 “file1 “和 “file2 “的例子- $ diff -y  file1 file2
This is the first line in file      This is the first line in file
This is the second line in file     This is the second line in file
This is the third line in file      This is the third line in file
This is the fourth line in file     | This is the fourth line in filex
This is the fifth line in file      | This is the fifth line in filex
This is the sixth line in file      This is the sixth line in file


## 使用sdiff命令

sdiff命令与diff命令类似，但它将两个文件之间的差异合并为一个输出。要使用sdiff命令，请在命令后面输入你要比较的两个文件的名称，像这样——。

$sdiff file1 file2  输出将显示两个文件之间的差异，文件中的每一行都会并排显示。任何不同的行将以红色突出显示，并标有符号，表明它们来自哪个文件。 下面是一个使用sdiff命令比较两个文件（file1和file2）的例子。 $ sdiff file1 file
This is the first line in file       This is the first line in file
This is the second line in file      This is the second line in file
This is the third line in file       This is the third line in file
This is the fourth line in file      | This is the fourth line in filex
This is the fifth line in file       | This is the fifth line in filex
This is the sixth line in file       This is the sixth line in file


## 使用vim文本编辑器

vim文本编辑器是在Linux上处理文件的一个流行和强大的工具。它可以使用”-o “或”-O “标志来并排查看两个文件。要在vim中并排查看两个文件，请在两个文件的名称后输入命令，如： -o

$vim -o file1 file2  这将在一个窗口中打开这两个文件，文件将并排出现。你可以使用 “Ctrl+w “命令在文件中导航。下面是一个使用vim在单个窗口中并排查看两个文件，即file1和file2的例子。 $ vim -O file1 file2


## 使用emacs文本编辑器

$emacs -nw file1 file2  这将在emacs的不同窗口中打开这两个文件。你可以用 “Ctrl+x “或”. “在窗口之间导航。 下面是一个用emacs并排显示两个文件，”file1 “和 “file2 “的例子。 $ emacs -nw file1 file2


• 回顶