Finding the differences between two text files

The command diff <file1> <file2> displays all differences between the two files <file1> and <file2>. It has many useful options.

Here is an example showing the use of diff on two file that differ only in a few lines.

[alice@onyx ~]$ cat list1 
1040 1680x1050.jpg
   4 log1
  16 logoCOENCS.png
   0 testfile1
   0 listing

[alice@onyx ~]$ cat list2
1040 1680x1050.jpg
   4 log2
1112 metageek_splash_screen.jpg
   0 testfile1
   0 tt

[alice@onyx ~]$ diff list1 list2
2,3c2,3
<    4 log1
<   16 logoCOENCS.png
---
>    4 log2
> 1112 metageek_splash_screen.jpg
5c5
<    0 listing
---
>    0 tt
[alice@onyx ~]$

The tag 2,3c2,3 (c stands for change) tells the lines numbers from the first file that need to be changed to match the line numbers from the second file.

The diff command has several options. It can ignore white space, ignore case, have the output be side by side and others documented on its man page.