diff analyzes two files and prints the lines that are different. Essentially, it outputs a set of instructions for how to change one file in order to make it identical to the second file.
diff file1.txt file2.txt
The first line of the diff output will contain:
- line numbers corresponding to the first file,
- a letter (a for add, c for change, or d for delete), and
- line numbers corresponding to the second file.
In our output above, “2,4c2,4” means: “Lines 2 through 4 in the first file need to be changed in order to match lines 2 through 4 in the second file.” It then tells us what those lines are in each file:
- Lines preceded by a < are lines from the first file;
- lines preceded by > are lines from the second file.
The three dashes (“—“) merely separate the lines of file 1 and file 2.