diff

diff compares two text files as a unified diff; the bundled patch command applies that change only when the source context still matches. Saving a patch and replacing an original file are explicit operations.

DevelopmentVersion 1.1.3StableAliases: patch
lil-terminal

Overview

Treat diff and patch as two halves of one review cycle: inspect what changed, keep a patch when it is useful, then apply it to a new destination before choosing whether the original should be replaced.

Review the change before applying it

A useful sequence is diff old.php new.php -o change.patch, then patch old.php change.patch. The default patch target is a separate .patched file; -r is the explicit step that replaces the source.

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 and apply

diff old.php new.php -o change.patch saves the reviewed change without modifying either source file. patch old.php change.patch writes a separate .patched result by default; use -o <dst> for another destination. Replacing the original requires -r.

Limits and safety

Each compared text file is limited to 4 MiB and 20000 lines, and binary input is rejected. A generated diff larger than 4 MiB is not returned. During patching, every context line is checked before anything is written, so a patch created for different source text fails instead of being forced onto it.

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.

Show a unified text diff with three context lines

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.3
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.

Show a unified text diff with three context lines
cd \sandbox | diff workspace/original.txt workspace/updated.txt
--- workspace/original.txt
+++ workspace/updated.txt
@@ -1,2 +1,2 @@
-alpha
+alpha reviewed
Set context from 0 to 20 lines
diff workspace/original.txt workspace/updated.txt -c 1
--- workspace/original.txt
+++ workspace/updated.txt
@@ -1,2 +1,2 @@
-alpha
+alpha reviewed
Report only whether the files differ
diff workspace/original.txt workspace/updated.txt -q
Different  yes
Old        workspace/original.txt
New        workspace/updated.txt
Save the unified diff as a patch file
diff workspace/original.txt workspace/updated.txt -o tmp/workspace.patch
Saved  tmp/workspace.patch
Size   148 B
Apply a unified patch into <file>.patched
patch workspace/original.txt tmp/workspace.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.

Write the patched text to another file
patch workspace/original.txt tmp/workspace.patch -o 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.

Allow an existing non-replacing output file to be replaced
patch workspace/original.txt tmp/workspace.patch -o tmp/current.txt -f
Source   workspace/original.txt
Patched  tmp/current.txt
Replace  explicit

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

Atomically replace the original file
patch workspace/original.txt tmp/workspace.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.

Handle a missing comparison file
diff missing.txt workspace/updated.txt
File not found: missing.txt

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.32026-08-08

First stable release

Current stable release of diff. diff compares two text files as a unified diff; the bundled patch command applies that change only when the source context still matches.