[Previous] [Contents] [Index] [Next]

Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.


Compare two files, line by line (GNU)


diff [option] file1 file2


Ignore case differences in the contents of the files.
Ignore case when comparing filenames.
Consider case when comparing filenames.
Ignore changes due to tab expansion.
Ignore changes in the amount of white space.
Ignore all white space.
Ignore changes whose lines are all blank.
Ignore changes whose lines all match the given regular expression.
Strip trailing carriage returns from the input.
Treat all files as text.
-C num
Output num (default 3) lines of copied context.
-U num or --unified[=num]
Output num (default 3) lines of unified context.
--label label
Use label instead of the filename in the output. You can specify this option twice; the first applies to file1, and the second to file2.
Show which C function each change is in.
Show the most recent line that matches the given regular expression.
Output only whether or not the files differ.
Output an ed script.
Display the differences in the normal format.
Display the differences in RCS format.
Display the output in two columns.
-W num
Output at most num (default 130) print columns.
Output only the left column of common lines.
Don't display any lines that are common to both files.
-D name
Output merged file to show #ifdef name differences.
Use the given format to output groups of lines in an if-then-else format. GTYPE can be old, new, changed, or unchanged.

GFMT may contain:

Lines from file1.
Lines from file2.
Lines common to file1 and file2.
Use the given printf-style specification for the given letter. The letters are as follows for the new group; use lowercase letters for the old group:
  • F -- the first line number
  • L -- the last line number
  • N -- the number of lines = L-F+1
  • E -- F-1
  • M -- L+1.
A literal %.
The single character, C.
The character with the given octal code, OOO.
Use the given format to output all input lines in an if-then-else format.
Use the given format to output individual lines in an if-then-else format. LTYPE can be old, new, or unchanged. LFMT may contain:
Contents of the line.
Contents of the line, excluding any trailing newline.
Use the given printf-style specification for input line numbers.
A literal %.
The single character, C.
The character with the given octal code, OOO.
Pass the output through pr to paginate it.
Expand tabs into spaces in the output.
Make tabs line up by prepending a tab.
Recursively compare any subdirectories found.
Treat absent files as being empty.
Treat absent first files as being empty.
Report when two files are the same.
-x pattern
Exclude files that match the given pattern.
-X file
Exclude files that match any pattern in file.
-S file
Start with file when comparing directories.
Compare file1 to all operands. The file1 argument can also be the name of a directory.
Compare all operands to file2. The file2 argument can also be the name of a directory.
Keep num lines of the common prefix and suffix.
Try hard to find a smaller set of changes.
Assume large files and many scattered small changes.
Output version information.
Display a help message.
file1, file2
Pathnames of the files to be compared. These can be in the following forms:

If you specify the --from-file or --to-file option, there are no restrictions on the files. If you specify a dash (-) instead of a filename, diff reads from standard input.


The diff utility reports the differences between two files.

Note: If you use diff to compare binary files, diff simply reports whether or not the files are different. If you want to see the differences between two binary files, use cmp.

For any two files, there may be several correct interpretations of the differences between them. The diff utility attempts to generate the smallest number of additions, changes, and deletions required to convert file1 into file2. No output is produced if the files are identical.

Note: This utility is subject to the GNU Public License (GPL). We've included it for use on development systems.

For detailed documentation about diff, see the GNU website at http://www.gnu.org/.

Exit status:

No differences were found.
Differences were found.
An error occurred.

Contributing author:

GNU; report bugs to bug-gnu-utils@gnu.org.

See also:

cksum, cmp, diff3, wc

[Previous] [Contents] [Index] [Next]