# diff: see what changed between two files

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/diff-basics-full-en
diff reports line differences between two inputs and exits 0 when they match, 1 when they differ, 2 on trouble.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-42-A, TE-42-B and TE-42-C. The expected non-zero exit is TE-42-C (exit status 1). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-42-A: diff exit status: 0 same, 1 different, 2 trouble

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'a\n' > x; printf 'a\n' > y; printf 'b\n' > z
```

Command:

```bash
diff -q x y >/dev/null; echo same=$?; diff -q x z >/dev/null; echo diff=$?; diff -q x missing >/dev/null 2>&1; echo trouble=$?
```

Recorded output:

```
same=0
diff=1
trouble=2
```

### TE-42-B: diff -u shows a changed line as a minus line and a plus line under a hunk header

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'a\n' > x; printf 'b\n' > z
```

Command:

```bash
diff -u x z | tail -n +3
```

Recorded output:

```
@@ -1 +1 @@
-a
+b
```

Exit status: 0. This status and the output match what was written before the run. The status is that of tail, the last command in the pipe. diff -u itself exits 1.

### TE-42-C: expected non-zero exit: diff -q reports that two files differ and exits with status 1

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
printf 'a\n' > x; printf 'b\n' > z
```

Command:

```bash
diff -q x z
```

Recorded output:

```
Files x and z differ
```

Exit status: 1. This status and the output match what was written before the run.

TE-42-B: diff -u prints two header lines first, and tail -n +3 removed them. What is left is the hunk header @@ -1 +1 @@, the removed line -a and the added line +b. TE-42-C: by the setup, x holds a and z holds b. diff -q x z printed Files x and z differ and exited with status 1, which means the files differ.

## Limits

A difference is a normal result, not a failure.

## Source

- https://www.gnu.org/software/diffutils/manual/

## Evidence

- `TE-42-A`: diff exit status: 0 same, 1 different, 2 trouble

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-42-A` | diff exit status: 0 same, 1 different, 2 trouble | 0 | PASS | `ff8cf62d1b76` |
| `TE-42-B` | diff -u shows a changed line as a minus line and a plus line under a hunk header | 0 | PASS | `bb380314e71c` |
| `TE-42-C` | expected non-zero exit: diff -q reports that two files differ and exits with status 1 | 1 | PASS | `7c9707b05766` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [mkdir, cp, mv and rm: the basic file commands](https://kairos-2z6s.onrender.com/res/file-commands-full-en)
- [awk basics: split records into fields](https://kairos-2z6s.onrender.com/res/awk-basics-full-en)
- [Bash script arguments and functions: $1, $@, shift and return codes](https://kairos-2z6s.onrender.com/res/bash-arguments-functions-full-en)
- [Deleting .env in a new commit does not hide the key](https://kairos-2z6s.onrender.com/res/deleted-env-still-in-history-en)
- [find: list files by name and sort the result](https://kairos-2z6s.onrender.com/res/find-basics-full-en)
- [curl basics: fetch a page, save it, read the status code](https://kairos-2z6s.onrender.com/res/curl-basics-full-en)
