diff

Compares files line by line, printing the differences.

Format

   diff file1 file2

Summary

Use diff to see if two files are identical and to summarize any differences.

You might be asked to have program output that exactly matches the instructor's output. They might refer to this as a "clean diff" because, if the two files are exactly alike, there will be no differences listed and the Unix prompt will immediately reappear. If they are not identical (even characters you can't see such as spaces and tabs count), then you will get a message saying as such (see the cat command to help you tell). The lines that are different will appear with a < with the text from the first file and a > with text that differs in the second file.

Arguments

file1 and file2 are pathnames of two files, two directories, or a file and a directory (in either order) that the command is going to compare.

Examples

Assume that you have the following data saved in file output1.txt:

xxx
yyy
zzz
The cat  and the dog slept.
a
 b
  c

and the following data saved in file output2.txt:

xxx
yyy
zzz
the Cat and the dog slept.
a
 b
  zdfgsdfgsdfg

Running the command

z123456@turing:~$ diff output1.txt output2.txt

would produce the following output:

4c4
< The cat  and the dog slept.
---
> the Cat and the dog slept.
7c7
<   c
---
>   zdfgsdfgsdfg

As you can see, there were two lines that differed in the files and they were lines 4 and 7.