PROPHET/OS
NAME
diff: writes what stands in the one file and not in the other, in unified form
SYNOPSIS
diff [-r] [-q] [-k N] <a> <b> diff selbsttest
DESCRIPTION
Writes what stands in the one file and not in the other, in unified form: - is a line that goes, + one that comes, a blank one that stays.
-r both paths are directories, and it goes into them -q only says whether they differ, not what -k N lines of context around a change, 3 by default
Exit 0 when everything is equal, 1 when something differs or was not compared, 2 when it could not start at all.
What it does better than the original
**Two lines that look the same and are not.** A tab against three blanks, a carriage return at the end: the original prints both lines and leaves the reader to stare at them. Here a third line follows, beginning with ?, and it names the first byte where the two part and what stands there on both sides.
**No silent heuristic.** The original switches to a faster and longer script on large inputs without saying so, so its output depends on the size of the file. Here the script is minimal, or the line the search reached its bound stands in the output and the block is given whole. The answer stays correct either way, and which of the two it is can be read.
**What was not compared is named.** A file that lies on one side only (with its kind), one that is longer than this diff can hold, one that carries a zero byte, a name that is a directory here and a file there: each one is a line with its reason. Nothing is skipped silently and nothing reads Binary files differ.
**A summary a script can read**, as the last line: how many lines go, how many come, how many files differ, how many were not compared. A build step counts instead of parsing a diff.
The bounds, and they are said out loud
8192 lines per file, which is more than the largest file of this tree (os/test/net.c, 7528 lines on 2026-10-03), and 1024 blocks of change per pair of files. The text itself is **not** held: per line eight bytes, and what stands in it is read from the file when it is needed, which is why the whole program carries 356 KB and not a megabyte.
The computation is lib/text/diff.c (Myers 1986 with the middle snake) and it is **bound and not carried**: the same artefact serves the next program that compares sequences.
diff selbsttest drives eleven cases without a file: equal, both empty, only added, only deleted, one line changed, two places apart, insertion in the middle, deletion at the end, nothing in common, the ABCABBA against CBABAC of the paper, and a long equal run between two different ends.
EXAMPLE
$ diff --help diff [-r] [-q] [-k N] <a> <b> writes what stands in a and not in b, in unified form -r both are directories, and it goes into them -q only says whether they differ, not what -k N lines of context around a change, 3 by default selbsttest drives its own eleven cases