The diff command

The diff command is used to find differences between two files. Let's see a few examples to find out its usage. The content of file1 is as follows:

I go for shopping on Saturday 
I rest completely on Sunday 
I use Facebook & Twitter for social networking 

The content of file2 is as follows:

Today is Monday. 
I go for shopping on Saturday 
I rest completely on Sunday 
I use Facebook & Twitter for social networking 

Type the diff command:

    $ diff file1 file2

The output will be this:

    0a1
    > Today is Monday

In the output, 0a1 tells us that line number 1 is added in file2. Let's see another example with line deletion. The content of file1 is as follows:

Today is Monday I go for shopping on Saturday I rest completely on Sunday I use ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.