diff

diff compares two versions of a text file and shows lines added or removed. -q answers only whether they differ; -c 0 shows only changed lines. Save a reviewable unified patch with -o <patch>.

DevelopmentVersion 1.1.4StableAliases: patch
lil-terminal

Overview

The diff module also installs patch. By default, patch <file> <patch> creates a separate .patched file. Use -o <dst> for another destination and -f only if that output already exists. -r explicitly replaces the input file.

Review the change before applying it

A patch records surrounding text. Before writing, the command checks that this text still matches the source; a patch from another revision fails instead of blindly editing it. Both files must be readable text, at most 4 MiB and 20000 lines.

Syntax

lil-terminal
diff <old> <new> [options]

Reference

diff <old> <new>

show a unified text diff with three context lines

diff <old> <new> -c <lines>

set context from 0 to 20 lines

diff <old> <new> -q

report only whether the files differ

diff <old> <new> -o <patch>

save the unified diff as a patch file

patch <file> <patch>

apply a unified patch into <file>.patched

patch <file> <patch> -o <dst>

write the patched text to another file

patch <file> <patch> -r

atomically replace the original file

patch <file> <patch> -f

allow an existing non-replacing output file to be replaced

Review a change before applying it

diff compares two versions of a text file and shows lines added or removed. -q answers only whether they differ; -c 0 shows only changed lines. Save a reviewable unified patch with -o <patch>.

One module, two commands

The diff module also installs patch. By default, patch <file> <patch> creates a separate .patched file. Use -o <dst> for another destination and -f only if that output already exists. -r explicitly replaces the input file.

Why context matters

A patch records surrounding text. Before writing, the command checks that this text still matches the source; a patch from another revision fails instead of blindly editing it. Both files must be readable text, at most 4 MiB and 20000 lines.

Interactive sandbox preview

Run the prepared examples directly on the page. Their results are prebuilt and shown in the browser; no terminal command is executed on the server.

Compare two file versions

Install and manage

Install the current compatible version. Choose Base for the complete feature set or Minimum for the reduced package; use upgrade to update a module that is already installed.

Base and Minimum are two packages of the same current module release, not separate command versions.

Base package

Install the complete package with local command reference and every published mode.

install diff
Minimum package

Install the reduced package. Local reference is omitted; help <cmd> -i opens the current server reference.

install diff -m
Exact public version

Install exactly this published version.

install diff -v 1.1.4
Check or update

Ask upgrade to check compatibility and replace the installed block only when needed.

upgrade diff
Remove module

Remove the extension block while leaving the core and unrelated modules intact.

install diff -u

Examples

Examples are copyable command lines, not actions executed by this website. Review paths, permissions and destructive flags before running them on a real project.

Compare two file versions
cd \sandbox | diff workspace/original.txt workspace/updated.txt
--- workspace/original.txt
+++ workspace/updated.txt
@@ -1,3 +1,4 @@
 alpha
-beta
+beta updated
 gamma
+delta
Diff without context
diff \sandbox\workspace\original.txt \sandbox\workspace\updated.txt -c 0
--- workspace/original.txt
+++ workspace/updated.txt
@@ -2 +2 @@
-beta
+beta updated
@@ -3,0 +4 @@
+delta
Check only if files differ
diff \sandbox\workspace\original.txt \sandbox\workspace\updated.txt -q
Different
Save a unified patch
diff \sandbox\workspace\original.txt \sandbox\workspace\updated.txt -o \sandbox\tmp\workspace.patch
Saved  tmp/workspace.patch
Size   110 B
Apply patch to separate file
patch \sandbox\workspace\original.txt \sandbox\workspace\change.patch
Source   workspace/original.txt
Patched  workspace/original.txt.patched

patch is supplied by the diff module; it applies a controlled unified diff without depending on a system patch binary.

Choose patch output filename
patch \sandbox\workspace\original.txt \sandbox\workspace\change.patch -o \sandbox\tmp\patched.txt
Source   workspace/original.txt
Patched  tmp/patched.txt

patch is supplied by the diff module; it applies a controlled unified diff without depending on a system patch binary.

Replace existing patch output
patch \sandbox\workspace\original.txt \sandbox\workspace\change.patch -o \sandbox\tmp\current.txt -f
Source   workspace/original.txt
Patched  tmp/current.txt

patch is supplied by the diff module; it applies a controlled unified diff without depending on a system patch binary.

Replace the original explicitly
patch \sandbox\workspace\original.txt \sandbox\workspace\change.patch -r
Source   workspace/original.txt
Patched  workspace/original.txt

patch is supplied by the diff module; it applies a controlled unified diff without depending on a system patch binary.

Reject a mismatched patch
patch \sandbox\workspace\updated.txt \sandbox\workspace\change.patch
Patch deletion mismatch

patch is supplied by the diff module; it applies a controlled unified diff without depending on a system patch binary.

Handle missing input
diff \sandbox\missing.txt \sandbox\workspace\updated.txt
File not found
Reject conflicting diff options
diff \sandbox\workspace\original.txt \sandbox\workspace\updated.txt -q -o \sandbox\tmp\bad.patch
Choose -q or -o

File used in this example: sandbox/workspace/original.txt

The example uses a file or directory from the protected /sandbox/ documentation workspace.

alpha
beta
gamma

Related documentation

Current public release

v1.1.42026-11-01

Production refinement

Current stable release of diff. diff compares two versions of a text file and shows lines added or removed.