Linux Diff Command Tutorial with Examples To Compare Two Text File


Comparing files line by line can be done with tool named diff. There are a lot of different options provided by diff. We will look most popular and useful features in this tutorial.


diff have simple syntax. There are options which we will look later and files to be compared.

Compare Two Files

In this example we will compare two files line by line

If there is no output after diff operation this means that there is no difference between files.

In this output we see that one line is different. > means second file have one extra line

  • 3a4 means after line 3 line 4 is added

We change file and compare again with the same command



  • 3d2 Lines 3 in the file1 need to be deleted in order to match line 2 in the file2
  • 4a4 From file2 delete line 4 to match first file line 4

View Verbose Diff

We can list all lines of two files with which lines will added or deleted both files to match each other.

Unified Mode

In unified view only one file is shown with related changes like delete or add. It is simpler than verbose mode to review.

LEARN MORE  How To Create, Start, Stop, Manage Docker Containers In Linux

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)