Easy Tutorial
❮ Linux Comm Nc Linux Comm Pwd ❯

Linux diff Command

Linux Command Manual

The Linux diff command is used to compare the differences between files.

diff compares text files line by line to identify the similarities and differences. If directories are specified for comparison, diff will compare files with the same names within the directories but will not compare subdirectories.

Syntax

diff [-abBcdefHilnNpPqrstTuvwy][-&lt;number of lines>][-C &lt;number of lines>][-D &lt;macro name>][-I &lt;character or string>][-S <file>][-W <width>][-x &lt;file or directory>][-X <file>][--help][--left-column][--suppress-common-lines][file or directory1][file or directory2]

Parameters:

Example 1: Compare Two Files

[root@localhost test3]# diff log2014.log log2013.log 
3c3
< 2014-03
---
> 2013-03
8c8
< 2013-07
---
> 2013-08
11,12d10
< 2013-11
< 2013-12

The "3c3" and "8c8" indicate that log2014.log and log2013.log differ on lines 3 and 8, respectively. The "11,12d10" indicates that the first file has lines 11 and 12 that are not present in the second file.

Example 2: Side-by-Side Format Output

[root@localhost test3]# diff log2014.log log2013.log  -y -W 50
2013-01                 2013-01
2013-02                 2013-02
2014-03               | 2013-03
2013-04                 2013-04
2013-05                 2013-05
2013-06                 2013-06
2013-07                 2013-07
2013-07               | 2013-08
2013-09                 2013-09
2013-10                 2013-10
2013-11               <
2013-12               <
[root@localhost test3]# diff log2013.log log2014.log  -y -W 50
2013-01                 2013-01
2013-02                 2013-02
2013-03               | 2014-03
2013-04                 2013-04
2013-05                 2013-05
2013-06                 2013-06
2013-07                 2013-07
2013-08               | 2013-07
2013-09                 2013-09
2013-10                 2013-10
                      > 2013-11
                      > 2013-12

Explanation:

Linux Command Manual

❮ Linux Comm Nc Linux Comm Pwd ❯