Compare files line by line
Default Output#
diff file1.txt file2.txt
| Change | Description |
|---|---|
| r1ar2 | Append the lines at the position r2 in second file |
| to the position r1 in the first file. | |
| r1cr2 | Change the lines at position r1 with the lines |
| at the position r2 in the second file. | |
| r1dr2 | Delete the lines in the first file at position r1, which |
| would have appeared at range r2 in the second file. |
diff Change Commands
Context Format#
diff -c file1.txt file2.txt
| Indicator | Meaning |
|---|---|
| blank | A line shown for context. Doesn't indicate a difference. |
| - | A line deleted. Appears in first file, but not in second. |
| + | A line added. Apperas in second file but not in first. |
| ! | A line changed. Both versions will be displayed. |
diff Context Format Change Indicators
Unified Format#
diff -u file1.txt file2.txt
| Indicator | Meaning |
|---|---|
| blank | The line is shared by both files |
| - | The line was removed from first file |
| + | The line was added to the first file |
diff Unified Format Change Indicators
Preparing diff for use with patch#
diff -Naur old_file new_file > diff_file r option supports recursion
of directory tree