Compare two files, line by line (GNU)
diff [option] file1 file2
- -i
--ignore-case
- Ignore case differences in the contents of the files.
- --ignore-file-name-case
- Ignore case when comparing filenames.
- --no-ignore-file-name-case
- Consider case when comparing filenames.
- -E
--ignore-tab-expansion
- Ignore changes due to tab expansion.
- -b
--ignore-space-change
- Ignore changes in the amount of white space.
- -w
--ignore-all-space
- Ignore all white space.
- -B
--ignore-blank-lines
- Ignore changes whose lines are all blank.
- -I RE
--ignore-matching-lines=RE
- Ignore changes whose lines all match the given regular expression.
- --strip-trailing-cr
- Strip trailing carriage returns from the input.
- -a
--text
- Treat all files as text.
- -c
-C num
--context[=num]
- Output num (default 3) lines of copied context.
- -u
-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.
- -p
--show-c-function
- Show which C function each change is in.
- -F RE
--show-function-line=RE
- Show the most recent line that matches the given regular expression.
- -q
--brief
- Output only whether or not the files differ.
- -e
--ed
- Output an ed script.
- --normal
- Display the differences in the normal format.
- -n
--rcs
- Display the differences in RCS format.
- -y
--side-by-side
- Display the output in two columns.
- -W num
--width=num
- Output at most num (default 130) print columns.
- --left-column
- Output only the left column of common lines.
- --suppress-common-lines
- Don't display any lines that are common to both files.
- -D name
--ifdef=name
- Output merged file to show #ifdef name
differences.
- --GTYPE-group-format=GFMT
- 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.
- %[-][width][.[prec]]{doxX}letter
- 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 %.
- %c'C'
- The single character, C.
- %c'\OOO'
- The character with the given octal code, OOO.
- --line-format=LFMT
- Use the given format to output all input lines in an if-then-else format.
- --LTYPE-line-format=LFMT
- Use the given format to output individual lines in an if-then-else format.
LTYPE can be old, new, or
unchanged.
LFMT may contain:
- %L
- Contents of the line.
- %l
- Contents of the line, excluding any trailing newline.
- %[-][width][.[prec]]{doxX}n
- Use the given printf-style specification for input line
numbers.
- %%
- A literal %.
- %c'C'
- The single character, C.
- %c'\OOO'
- The character with the given octal code, OOO.
- -l
--paginate
- Pass the output through
pr
to paginate it.
- -t
--expand-tabs
- Expand tabs into spaces in the output.
- -T
--initial-tab
- Make tabs line up by prepending a tab.
- -r
--recursive
- Recursively compare any subdirectories found.
- -N
--new-file
- Treat absent files as being empty.
- --unidirectional-new-file
- Treat absent first files as being empty.
- -s
--report-identical-files
- Report when two files are the same.
- -x pattern
--exclude=pattern
- Exclude files that match the given pattern.
- -X file
--exclude-from=file
- Exclude files that match any pattern in file.
- -S file
--starting-file=file
- Start with file when comparing directories.
- --from-file=file1
- Compare file1 to all operands.
The file1 argument can also be the name of a directory.
- --to-file=file2
- Compare all operands to file2.
The file2 argument can also be the name of a directory.
- --horizon-lines=num
- Keep num lines of the common prefix and suffix.
- -d
--minimal
- Try hard to find a smaller set of changes.
- --speed-large-files
- Assume large files and many scattered small changes.
- -v
--version
- Output version information.
- --help
- Display a help message.
- file1, file2
- Pathnames of the files to be compared.
These can be in the following forms:
- file1 file2
- directory1 directory2
- directory file...
- file... directory
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.
|
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.
For detailed documentation about diff, see the GNU website at
http://www.gnu.org/.
- 0
- No differences were found.
- 1
- Differences were found.
- >1
- An error occurred.
GNU; report bugs to
bug-gnu-utils@gnu.org.
cksum,
cmp,
diff3,
wc