How-To Guide: Compare two files for differences using the Linux shell

Gbekeloluwa S. O. Olufotebi
2 min readAug 28, 2016

The diff command is used compare files line by line.

General Syntax

diff filename1 filename2

The diff command will compare filename1 and filename2.

Interpreting the output

We will use the following points to interpret the output of the doff command

  • It prints a message that uses a special notation (a for append, c for change, and d for delete) to describe how a set of lines has changed
  • The < character precedes lines from the first file
  • The > character precedes lines from the second file

Example Input Files

Diff Output

What it means:
3,4c3,4 means that lines 3 through 4 of the first file are changed and replaced by lines 3 through 4 in the second file

Some other examples

  • 0a1 means line one of the second file has to be added to the top of the first file to make both files the same
  • 1d0 means line one of the first file has to be deleted to make both files the same

--

--