# man > diff

---
type: CommandReference
command: diff
mode: man
section: 1
source: man-pages
---

## Quick Reference
- `diff {{path/to/old_file}} {{path/to/new_file}}` — Compare files (lists changes to turn old_file into new_file)
- `diff -w {{path/to/old_file}} {{path/to/new_file}}` — Compare files, ignoring white spaces
- `diff -y {{path/to/old_file}} {{path/to/new_file}}` — Compare files, showing differences side by side
- `diff -u {{path/to/old_file}} {{path/to/new_file}}` — Compare files in unified format (as used by git diff)
- `diff -r {{path/to/old_directory}} {{path/to/new_directory}}` — Recursively compare directories (shows names and changes)
- `diff -rq {{path/to/old_directory}} {{path/to/new_directory}}` — Compare directories, only show names of differing files
- `diff -a -u -N {{path/to/old_file}} {{path/to/new_file}} > {{path/to/diff.patch}}` — Create a patch file for Git, treating nonexistent files as empty
- `diff -d --color=always {{path/to/old_file}} {{path/to/new_file}}` — Compare files, output in color, try to find minimal changes

## Name
diff — compare files line by line

## Synopsis
`diff [OPTION]... FILES`

## Options
**Output format:**
- `-q, --brief` — report only when files differ
- `-s, --report-identical-files` — report when files are the same
- `-c, -C NUM, --context[=NUM]` — output NUM (default 3) lines of copied context
- `-u, -U NUM, --unified[=NUM]` — output NUM lines of unified context (default 3)
- `-y, --side-by-side` — output in two columns
- `--suppress-common-lines` — do not output common lines (with `-y`)
- `-p, --show-c-function` — show which C function each change is in
- `-F, --show-function-line RE` — show the most recent line matching RE
- `--label LABEL` — use LABEL instead of file name and timestamp
- `-t, --expand-tabs` — expand tabs to spaces in output
- `--tabsize=NUM` — tab stops every NUM (default 8) columns
- `--color[=WHEN]` — colorize output; WHEN is 'never', 'always', or 'auto' (plain `--color` means auto)

**Comparison behavior:**
- `-i, --ignore-case` — ignore case differences
- `-b, --ignore-space-change` — ignore changes in amount of white space
- `-w, --ignore-all-space` — ignore all white space
- `-B, --ignore-blank-lines` — ignore blank lines
- `-I, --ignore-matching-lines=RE` — ignore changes where all lines match RE
- `-E, --ignore-tab-expansion` — ignore changes due to tab expansion
- `-Z, --ignore-trailing-space` — ignore white space at line end
- `--strip-trailing-cr` — strip trailing carriage return on input
- `-a, --text` — treat all files as text
- `-d, --minimal` — try hard to find a smaller set of changes
- `--speed-large-files` — assume large files and many scattered changes
- `--horizon-lines=NUM` — keep NUM lines of common prefix and suffix

**Directory comparison and file selection:**
- `-r, --recursive` — recursively compare subdirectories
- `--no-dereference` — don't follow symbolic links
- `-N, --new-file` — treat absent files as empty
- `--unidirectional-new-file` — treat absent first files as empty
- `--ignore-file-name-case` — ignore case when comparing file names
- `--no-ignore-file-name-case` — consider case when comparing file names
- `-x, --exclude=PAT` — exclude files matching PAT
- `-X, --exclude-from=FILE` — exclude files matching any pattern in FILE
- `-S, --starting-file=FILE` — start with FILE when comparing directories
- `--from-file=FILE1` — compare FILE1 to all operands; FILE1 can be a directory
- `--to-file=FILE2` — compare all operands to FILE2; FILE2 can be a directory

**Merge/formatting (advanced):**
- `-D, --ifdef=NAME` — output merged file with '#ifdef NAME' diffs
- `--GTYPE-group-format=GFMT` — format GTYPE input groups with GFMT
- `--line-format=LFMT` — format all input lines with LFMT
- `--LTYPE-line-format=LFMT` — format LTYPE input lines with LFMT
  (See man page for format specifiers.)

**Miscellaneous:**
- `--help` — display help and exit
- `-v, --version` — output version information and exit

## Exit Codes
- `0` — files are the same
- `1` — files are different
- `2` — trouble (e.g., invalid option, read error)

## See Also
`wdiff(1)`, `cmp(1)`, `diff3(1)`, `sdiff(1)`, `patch(1)`