Display the differences between two files, or each corresponding file in two directories.
Each set of differences is called a "diff" or "patch". For files that are identical, &qt;diff&qt;&qt; normally produces no output; for binary (non-text) files, &qt;diff&qt;&qt; normally reports only that they are different.

SYNTAX
diff [options] from-file to-fileOPTIONS
Multiple single letter options (unless they take an argument) can be combined into a single command line word: so &qt;-ac&qt;&qt; is equivalent to &qt;-a -c&qt;&qt;.

-lines Show lines lines of context. This option is obsolete.

-a Treat all files as text and compare them line-by-
line, even if they do not seem to be text.

-b Ignore changes in amount of white space.

-B Ignore changes that just insert or delete blank
lines.

–brief
Report only whether the files differ, not the
details of the differences.

-c Use the context output format.

-C lines
–context[=lines]
Use the context output format, showing lines (an
integer) lines of context, or three if lines is not
given. For proper operation, patch typically needs
at least two lines of context.

–changed-group-format=format
Use format to output a line group containing dif-
fering lines from both files in if-then-else for-
mat.

-d Change the algorithm to perhaps find a smaller set
of changes. This makes diff slower (sometimes much
slower).

-D name
Make merged if-then-else format output, conditional
on the preprocessor macro name.

-e
–ed Make output that is a valid ed script.

–exclude=pattern
When comparing directories, ignore files and subdi-
rectories whose basenames match pattern.

–exclude-from=file
When comparing directories, ignore files and subdi-
rectories whose basenames match any pattern con-
tained in file.

–expand-tabs
Expand tabs to spaces in the output, to preserve
the alignment of tabs in the input files.

-f Make output that looks vaguely like an ed script
but has changes in the order they appear in the
file.

-F regexp
In context and unified format, for each hunk of
differences, show some of the last preceding line
that matches regexp.

–forward-ed
Make output that looks vaguely like an ed script
but has changes in the order they appear in the
file.

-h This option currently has no effect; it is present
for Unix compatibility.

-H Use heuristics to speed handling of large files
that have numerous scattered small changes.

–horizon-lines=lines
Do not discard the last lines lines of the common
prefix and the first lines lines of the common suf-
fix.

-i Ignore changes in case; consider upper- and lower-
case letters equivalent.

-I regexp
Ignore changes that just insert or delete lines
that match regexp.

–ifdef=name
Make merged if-then-else format output, conditional
on the preprocessor macro name.

–ignore-all-space
Ignore white space when comparing lines.

–ignore-blank-lines
Ignore changes that just insert or delete blank
lines.

–ignore-case
Ignore changes in case; consider upper- and lower-
case to be the same.

–ignore-matching-lines=regexp
Ignore changes that just insert or delete lines
that match regexp.

–ignore-space-change
Ignore changes in amount of white space.

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

-l Pass the output through pr to paginate it.

-L label
–label=label
Use label instead of the file name in the context
format and unified format headers.

–left-column
Print only the left column of two common lines in
side by side format.

–line-format=format
Use format to output all input lines in in-then-
else format.

–minimal
Change the algorithm to perhaps find a smaller set
of changes. This makes diff slower (sometimes much
slower).

-n Output RCS-format diffs; like -f except that each
command specifies the number of lines affected.

-N
–new-file
In directory comparison, if a file is found in only
one directory, treat it as present but empty in the
other directory.

–new-group-format=format
Use format to output a group of lines taken from
just the second file in if-then-else format.

–new-line-format=format
Use format to output a line taken from just the
second file in if-then-else format.

–old-group-format=format
Use format to output a group of lines taken from
just the first file in if-then-else format.

–old-line-format=format
Use format to output a line taken from just the
first file in if-then-else format.

-p Show which C function each change is in.

-P When comparing directories, if a file appears only
in the second directory of the two, treat it as
present but empty in the other.

–paginate
Pass the output through pr to paginate it.

-q Report only whether the files differ, not the
details of the differences.

-r When comparing directories, recursively compare any
subdirectories found.

–rcs Output RCS-format diffs; like -f except that each
command specifies the number of lines affected.

–recursive
When comparing directories, recursively compare any
subdirectories found.

–report-identical-files
-s Report when two files are the same.

-S file
When comparing directories, start with the file
file. This is used for resuming an aborted compar-
ison.

–sdiff-merge-assist
Print extra information to help sdiff. sdiff uses
this option when it runs diff. This option is not
intended for users to use directly.

–show-c-function
Show which C function each change is in.

–show-function-line=regexp
In context and unified format, for each hunk of
differences, show some of the last preceding line
that matches regexp.

–side-by-side
Use the side by side output format.

–speed-large-files
Use heuristics to speed handling of large files
that have numerous scattered small changes.

–starting-file=file
When comparing directories, start with the file
file. This is used for resuming an aborted compar-
ison.

–suppress-common-lines
Do not print common lines in side by side format.

-t Expand tabs to spaces in the output, to preserve
the alignment of tabs in the input files.

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

–text Treat all files as text and compare them line-by-
line, even if they do not appear to be text.

-u Use the unified output format.

–unchanged-group-format=format
Use format to output a group of common lines taken
from both files in if-then-else format.

–unchanged-line-format=format
Use format to output a line common to both files in
if-then-else format.

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

-U lines
–unified[=lines]
Use the unified output format, showing lines (an
integer) lines of context, or three if lines is not
given. For proper operation, patch typically needs
at least two lines of context.

-v
–version
Output the version number of diff.

-w Ignore white space when comparing lines.

-W columns
–width=columns
Use an output width of columns in side by side for-
mat.

-x pattern
When comparing directories, ignore files and subdi-
rectories whose basenames match pattern.

-X file
When comparing directories, ignore files and subdi-
rectories whose basenames match any pattern con-
tained in file.

-y Use the side by side output format.In the simplest case, diff compares the contents of the two files from-file and to-file. A file name of – stands for text read from the standard input.

If from-file is a directory and to-file is not, diff compares the file in from-file whose file name is that of to-file, and vice versa. The non-directory file must not be -.

If both from-file and to-file are directories, diff compares corresponding files in both directories, in alphabetical order; this comparison is not recursive unless the -r or –recursive option is given.

GNU &qt;diff&qt;&qt; can show whether files are different without detailing the differences.
It also provides ways to suppress certain kinds of differences that are not important to you.

Most commonly, such differences are changes in the amount of white space between words or lines. &qt;diff&qt;&qt; also provides ways to suppress differences in alphabetic case or in lines that match a regular expression that you provide.

These options can accumulate; for example, you can ignore changes in both white space and alphabetic case.

End -of-Line markers
In operating systems that distinguish between text and binary files, &qt;diff&qt;&qt; normally reads and writes all data as text.

Use the &qt;–binary&qt;&qt; option to force &qt;diff&qt;&qt; to read and write binary data instead. This option has no effect on a Posix-compliant system like GNU or traditional Unix. However, many personal computer operating systems represent the end of a line with a carriage return followed by a newline.

On such systems, &qt;diff&qt;&qt; normally ignores these carriage returns on input and generates them at the end of each output line, but with the &qt;–binary&qt;&qt; option &qt;diff&qt;&qt; treats each carriage return as just another input character, and does not generate a carriage return at the end of each output line.

This can be useful when dealing with non-text files that are meant to be interchanged with Posix-compliant systems.

Suppressing Differences in Blank and Tab Spacing
The &qt;-b&qt;&qt; and &qt;–ignore-space-change&qt;&qt; options ignore white space at line end, and considers all other sequences of one or more white space characters to be equivalent.
With these options, &qt;diff&qt;&qt; considers the following two lines to be equivalent, where &qt;$&qt;&qt; denotes the line end:

Here lyeth muche rychnesse in lytell space. — John Heywood$
Here lyeth muche rychnesse in lytell space. — John Heywood $

The &qt;-w&qt;&qt; and &qt;–ignore-all-space&qt;&qt; options are stronger than &qt;-b&qt;&qt;. They ignore difference even if one file has white space where the other file has none. "White space" characters include tab, newline, vertical tab, form feed, carriage return, and space; some locales may define additional characters to be white space.
With these options, &qt;diff&qt;&qt; considers the following two lines to be equivalent, where &qt;$&qt;&qt; denotes the line end and &qt;^M&qt;&qt; denotes a carriage return:

Here lyeth muche rychnesse in lytell space.– John Heywood$
He relyeth much erychnes seinly tells pace. –John Heywood

GNU &qt;diff&qt;&qt; can treat lowercase letters as equivalent to their uppercase counterparts, so that, for example, it considers &qt;Funky Stuff&qt;&qt;, &qt;funky STUFF&qt;&qt;, and &qt;fUNKy stuFf&qt;&qt; to all be the same.
To request this, use the &qt;-i&qt;&qt; or &qt;–ignore-case&qt;&qt; option.

Suppressing Lines Matching a Regular Expression
To ignore insertions and deletions of lines that match a regular expression, use the &qt;-I REGEXP&qt;&qt; or &qt;–ignore-matching-lines=REGEXP&qt;&qt; option.
You should escape regular expressions that contain shell metacharacters to prevent the shell from expanding them.

For example, &qt;diff -I &qt;&qt;^[0-9]&qt; ignores all changes to lines beginning with a digit.

However, &qt;-I&qt;&qt; only ignores the insertion or deletion of lines that contain the regular expression if every changed line in the hunk–every insertion and every deletion–matches the regular expression.

In other words, for each nonignorable change, &qt;diff&qt;&qt; prints the complete set of changes in its vicinity, including the ignorable ones. You can specify more than one regular expression for lines to ignore by using more than one &qt;-I&qt;&qt; option. &qt;diff&qt;&qt; tries to match each line against each regular expression, starting with the last one given.

Summarizing Which Files Differ
When you only want to find out whether files are different, and you don&qt;&qt;t care what the differences are, you can use the summary output format.
In this format, instead of showing the differences between the files, &qt;diff&qt;&qt; simply reports whether files differ.
The &qt;-q&qt;&qt; and &qt;–brief&qt;&qt; op
tions select this output format.
This format is especially useful when comparing the contents of two directories. It is also much faster than doing the normal line by line comparisons, because &qt;diff&qt;&qt; can stop analyzing the files as soon as it knows that there are any differences.
You can also get a brief indication of whether two files differ by using &qt;cmp&qt;&qt;.

Using diff to patch a file
To show context around the differing lines GNU &qt;diff&qt;&qt; provides these output formats

Normal Format: An output format that shows each hunk of differences without any surrounding context
Context Format:: An output format that shows surrounding lines.
Unified Format:: A more compact output format that shows context.

&qt;patch&qt;&qt; can apply diffs by searching in the files for the lines of context around the differing lines; if those lines are actually a few lines away from where the diff says they are, &qt;patch&qt;&qt; can adjust the line numbers accordingly and still apply the diff correctly.

For more on patching files and producing commands that direct the &qt;ed&qt;&qt; text editor to edit a file – see &qt;info diff&qt;&qt;