What command is used to compare two files line by line?

The story behind the answer

What command is used to compare two files line by line? The answer is `diff`.

The Unix `diff` command compares two files and reports the changes needed to transform the first into the second. Its traditional output is line-oriented: it identifies added, deleted, or changed lines rather than merely saying whether the files match. This makes it especially useful for source code, configuration files, documentation, and other text.

`diff` originated at AT&T Bell Laboratories and was released in 1974. Its output later became the foundation of patch files, which can be applied with the separate `patch` command. Modern implementations can produce several formats, including unified diffs, the familiar format used by code-review tools and version-control systems.

`cmp` is a frequent confusion because it compares files byte by byte and is useful when an exact binary comparison is wanted. `comm` compares two sorted files line by line, but organizes lines into common and unique columns rather than presenting a general change report. `diff` is therefore the standard answer for ordinary line-by-line file comparison.

Source: Wikipedia · fact-checked Sept. 2026

Add question to a list

Choose a list to keep this question in: