The diff command shows differences in file content by comparing two files line by line and outputting the changes between them. The output typically includes:
-
Lines that are different:
- Lines that are present in one file but not the other are marked with a
>or<symbol. - Lines that have been changed are shown with a
-for the line removed and a+for the line added.
- Lines that are present in one file but not the other are marked with a
-
Context lines:
- By default,
diffshows a few lines of context around the changes to provide clarity on where the differences occur.
- By default,
For example, if you run diff file1.txt file2.txt, the output might look like this:
1c1
< This is a line in file1.
---
> This is a line in file2.
In this output:
- The
<indicates a line fromfile1.txt. - The
>indicates a line fromfile2.txt. - The
cindicates that the line has changed.
Using options like -u or -c can change the format to a unified or context format, respectively, which provides more context around the differences.
