diff
Text processing
Usage
diff -u [old] [new]Shows what changed between two files; the unified -u form is what patch and code review expect, and it exits 1 when they differ, which stops a script running under set -e.
Common flags
| Flag | Meaning |
|---|---|
| -u | Unified output, the format patch and code review expect |
| -r | Compare two directory trees |
| -q | Only say whether the files differ |
| -w | Ignore all whitespace |
| -i | Ignore case |
| -N | Treat a missing file as empty, which patches need |
Examples
diff -u old.conf new.conf > fix.patchWrites a patch file.
diff -rq dirA dirBLists which files differ between two trees.
diff <(sort a.txt) <(sort b.txt)Compares two files ignoring line order (bash).
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does diff do?
Shows what changed between two files; the unified -u form is what patch and code review expect, and it exits 1 when they differ, which stops a script running under set -e.
Q. How do I type it?
diff -u [old] [new] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man diff. This command sits under Text processing.
Related commands
man page: man diff