Go to the first, previous, next, last section, table of contents.
The format for running the @command{diff} command is:
diff options... files...
In the simplest case, two file names from-file and
to-file are given, and @command{diff} compares the contents of
from-file and to-file. A file name of `-' stands for
text read from the standard input. As a special case, `diff - -'
compares a copy of standard input to itself.
If one file is a directory and the other is not, @command{diff} compares
the file in the directory whose name is that of the non-directory.
The non-directory file must not be `-'.
If two file names are given and both are directories,
@command{diff} compares corresponding files in both directories, in
alphabetical order; this comparison is not recursive unless the
@option{-r} or @option{--recursive} option is given. @command{diff} never
compares the actual contents of a directory as if it were a file. The
file that is fully specified may not be standard input, because standard
input is nameless and the notion of "file with the same name" does not
apply.
If the @option{--from-file=file} option is given, the number of
file names is arbitrary, and file is compared to each named file.
Similarly, if the @option{--to-file=file} option is given, each
named file is compared to file.
@command{diff} options begin with `-', so normally file names
may not begin with `-'. However, @option{--} as an
argument by itself treats the remaining arguments as file names even if
they begin with `-'.
An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.
Below is a summary of all of the options that GNU @command{diff} accepts.
Most options have two equivalent names, one of which is a single letter
preceded by `-', and the other of which is a long name preceded by
`--'. Multiple single letter options (unless they take an
argument) can be combined into a single command line word: @option{-ac} is
equivalent to @option{-a -c}. Long named options can be abbreviated to
any unique prefix of their name. Brackets ([ and ]) indicate that an
option takes an optional argument.
- @option{-a}
-
- @option{--text}
-
Treat all files as text and compare them line-by-line, even if they
do not seem to be text. See section Binary Files and Forcing Text Comparisons.
- @option{-b}
-
- @option{--ignore-space-change}
-
Ignore changes in amount of white space. See section Suppressing Differences in Blank and Tab Spacing.
- @option{-B}
-
- @option{--ignore-blank-lines}
-
Ignore changes that just insert or delete blank lines. See section Suppressing Differences in Blank Lines.
- @option{--binary}
-
Read and write data in binary mode. See section Binary Files and Forcing Text Comparisons.
- @option{-c}
-
Use the context output format, showing three lines of context.
See section Context Format.
- @option{-C lines}
-
- @option{--context[=lines]}
-
Use the context output format, showing lines (an integer) lines of
context, or three if lines is not given. See section Context Format.
For proper operation, @command{patch} typically needs at least two lines of
context.
On older systems, @command{diff} supports an obsolete option
@option{-lines} that has effect when combined with @option{-c}
or @option{-p}. POSIX 1003.1-2001 (see section Standards conformance) does not allow this; use @option{-C lines}
instead.
- @option{--changed-group-format=format}
-
Use format to output a line group containing differing lines from
both files in if-then-else format. See section Line Group Formats.
- @option{-d}
-
- @option{--minimal}
-
Change the algorithm perhaps find a smaller set of changes. This makes
@command{diff} slower (sometimes much slower). See section @command{diff} Performance Tradeoffs.
- @option{-D name}
-
- @option{--ifdef=name}
-
Make merged `#ifdef' format output, conditional on the preprocessor
macro name. See section Merging Files with If-then-else.
- @option{-e}
-
- @option{--ed}
-
Make output that is a valid @command{ed} script. See section @command{ed} Scripts.
- @option{-E}
-
- @option{--ignore-tab-expansion}
-
Ignore changes due to tab expansion.
See section Suppressing Differences in Blank and Tab Spacing.
- @option{-f}
-
- @option{--forward-ed}
-
Make output that looks vaguely like an @command{ed} script but has changes
in the order they appear in the file. See section Forward @command{ed} Scripts.
- @option{-F regexp}
-
- @option{--show-function-line=regexp}
-
In context and unified format, for each hunk of differences, show some
of the last preceding line that matches regexp. See section Showing Lines That Match Regular Expressions.
- @option{--from-file=file}
-
Compare file to each operand; file may be a directory.
- @option{--help}
-
Output a summary of usage and then exit.
- @option{--horizon-lines=lines}
-
Do not discard the last lines lines of the common prefix
and the first lines lines of the common suffix.
See section @command{diff} Performance Tradeoffs.
- @option{-i}
-
- @option{--ignore-case}
-
Ignore changes in case; consider upper- and lower-case letters
equivalent. See section Suppressing Case Differences.
- @option{-I regexp}
-
- @option{--ignore-matching-lines=regexp}
-
Ignore changes that just insert or delete lines that match regexp.
See section Suppressing Lines Matching a Regular Expression.
- @option{--ignore-file-name-case}
-
Ignore case when comparing file names during recursive comparison.
See section Comparing Directories.
- @option{-l}
-
- @option{--paginate}
-
Pass the output through @command{pr} to paginate it. See section Paginating @command{diff} Output.
- @option{--label=label}
-
Use label instead of the file name in the context format
(see section Context Format) and unified format (see section Unified Format)
headers. See section RCS Scripts.
- @option{--left-column}
-
Print only the left column of two common lines in side by side format.
See section Controlling Side by Side Format.
- @option{--line-format=format}
-
Use format to output all input lines in if-then-else format.
See section Line Formats.
- @option{-n}
-
- @option{--rcs}
-
Output RCS-format diffs; like @option{-f} except that each command
specifies the number of lines affected. See section RCS Scripts.
- @option{-N}
-
- @option{--new-file}
-
In directory comparison, if a file is found in only one directory,
treat it as present but empty in the other directory. See section Comparing Directories.
- @option{--new-group-format=format}
-
Use format to output a group of lines taken from just the second
file in if-then-else format. See section Line Group Formats.
- @option{--new-line-format=format}
-
Use format to output a line taken from just the second file in
if-then-else format. See section Line Formats.
- @option{--old-group-format=format}
-
Use format to output a group of lines taken from just the first
file in if-then-else format. See section Line Group Formats.
- @option{--old-line-format=format}
-
Use format to output a line taken from just the first file in
if-then-else format. See section Line Formats.
- @option{-p}
-
- @option{--show-c-function}
-
Show which C function each change is in. See section Showing C Function Headings.
- @option{-q}
-
- @option{--brief}
-
Report only whether the files differ, not the details of the
differences. See section Summarizing Which Files Differ.
- @option{-r}
-
- @option{--recursive}
-
When comparing directories, recursively compare any subdirectories
found. See section Comparing Directories.
- @option{-s}
-
- @option{--report-identical-files}
-
Report when two files are the same. See section Comparing Directories.
- @option{-S file}
-
- @option{--starting-file=file}
-
When comparing directories, start with the file file. This is
used for resuming an aborted comparison. See section Comparing Directories.
- @option{--speed-large-files}
-
Use heuristics to speed handling of large files that have numerous
scattered small changes. See section @command{diff} Performance Tradeoffs.
- @option{--strip-trailing-cr}
-
Strip any trailing carriage return at the end of an input line.
See section Binary Files and Forcing Text Comparisons.
- @option{--suppress-common-lines}
-
Do not print common lines in side by side format.
See section Controlling Side by Side Format.
- @option{-t}
-
- @option{--expand-tabs}
-
Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files. See section Preserving Tab Stop Alignment.
- @option{-T}
-
- @option{--initial-tab}
-
Output a tab rather than a space before the text of a line in normal or
context format. This causes the alignment of tabs in the line to look
normal. See section Preserving Tab Stop Alignment.
- @option{--to-file=file}
-
Compare each operand to file; file may be a directory.
- @option{-u}
-
Use the unified output format, showing three lines of context.
See section Unified Format.
- @option{--unchanged-group-format=format}
-
Use format to output a group of common lines taken from both files
in if-then-else format. See section Line Group Formats.
- @option{--unchanged-line-format=format}
-
Use format to output a line common to both files in if-then-else
format. See section Line Formats.
- @option{--unidirectional-new-file}
-
When comparing directories, if a file appears only in the second
directory of the two, treat it as present but empty in the other.
See section Comparing Directories.
- @option{-U lines}
-
- @option{--unified[=lines]}
-
Use the unified output format, showing lines (an integer) lines of
context, or three if lines is not given. See section Unified Format.
For proper operation, @command{patch} typically needs at least two lines of
context.
On older systems, @command{diff} supports an obsolete option
@option{-lines} that has effect when combined with @option{-u}.
POSIX 1003.1-2001 (see section Standards conformance) does not allow
this; use @option{-U lines} instead.
- @option{-v}
-
- @option{--version}
-
Output version information and then exit.
- @option{-w}
-
- @option{--ignore-all-space}
-
Ignore white space when comparing lines. See section Suppressing Differences in Blank and Tab Spacing.
- @option{-W columns}
-
- @option{--width=columns}
-
Output at most columns (default 130) print columns per line in
side by side format. See section Controlling Side by Side Format.
- @option{-x pattern}
-
- @option{--exclude=pattern}
-
When comparing directories, ignore files and subdirectories whose basenames
match pattern. See section Comparing Directories.
- @option{-X file}
-
- @option{--exclude-from=file}
-
When comparing directories, ignore files and subdirectories whose basenames
match any pattern contained in file. See section Comparing Directories.
- @option{-y}
-
- @option{--side-by-side}
-
Use the side by side output format. See section Controlling Side by Side Format.
Go to the first, previous, next, last section, table of contents.