diff: Comparing Files
What changed?.
You have two versions of a file, and they look almost the same. What exactly changed? Reading both line by line is slow, and easy to get wrong. Diff spots the differences for you.

- Two versions of a file
- What changed?
- diff finds out
A side by side view
Here are two versions of a shopping list. Diff dash Y shows them side by side. A vertical bar marks a line that changed. Milk became oat milk, and cheese was replaced by apples. Lines with no mark are the same in both files. If a line had only been removed, or only added, diff would mark it with a less than, or a greater than sign.
diff -y -W 50 list-v1.txt list-v2.txt eggs eggs milk | oat milk bread bread cheese | apples
The unified format
Dash U gives the format programmers use, called unified. Lines starting with minus were removed, and lines starting with plus were added. Lines with a space didn't change. It's the same format Git uses, to show changes to code.
diff -u list-v1.txt list-v2.txt --- list-v1.txt 2026-01-05 09:00:00.000000000 +0000 +++ list-v2.txt 2026-01-05 09:00:00.000000000 +0000 @@ -1,4 +1,4 @@ eggs -milk +oat milk bread -cheese +apples
Diff tips
If the files are identical, diff prints nothing at all, and returns exit code zero. That makes it great for checking a backup. Dash Q only tells you whether files differ. And dash R compares whole folders.
| key | value |
|---|---|
| Same files | prints nothing, exit 0 |
| -y | side by side |
| -u | unified, like Git |
| -r | compare folders |
Summary
Diff shows exactly how two files differ. Dash Y side by side, and dash U in the unified format. Next, xargs, for feeding lists into commands.
Key takeaways- diff a b
- diff -y
- diff -u