Linux "diff" Command Line Options and Examples
compare files line by line

Compare FILES line by line. Mandatory arguments to long options are mandatory for short options too.


Usage:

diff [OPTION]... FILES






Command Line Options:

--normal
output a normal diff (the default)
diff --normal ...
-q
report only when files differ
diff -q ...
-s
report when two files are the same
diff -s ...
-c
output NUM (default 3) lines of copied context
diff -c ...
-u
output NUM (default 3) lines of unified context
diff -u ...
-e
output an ed script
diff -e ...
-n
output an RCS format diff
diff -n ...
-y
output in two columns
diff -y ...
-W
output at most NUM (default 130) print columns
diff -W ...
--left-column
output only the left column of common lines
diff --left-column ...
--suppress-common-lines
do not output common lines
diff --suppress-common-lines ...
-p
show which C function each change is in
diff -p ...
-F
show the most recent line matching RE
diff -F ...
--label
use LABEL instead of file name and timestamp (can be repeated)
diff --label ...
-t
expand tabs to spaces in output
diff -t ...
-T
make tabs line up by prepending a tab
diff -T ...
--tabsize
tab stops every NUM (default 8) print columns
diff --tabsize ...
--suppress-blank-empty
suppress space or tab before empty output lines
diff --suppress-blank-empty ...
-l
pass output through 'pr' to paginate it
diff -l ...
-r
recursively compare any subdirectories found
diff -r ...
--no-dereference
don't follow symbolic links
diff --no-dereference ...
-N
treat absent files as empty
diff -N ...
--unidirectional-new-file
treat absent first files as empty
diff --unidirectional-new-file ...
--ignore-file-name-case
ignore case when comparing file names
diff --ignore-file-name-case ...
--no-ignore-file-name-case
consider case when comparing file names
diff --no-ignore-file-name-case ...
-x
exclude files that match PAT
diff -x ...
-X
exclude files that match any pattern in FILE
diff -X ...
-S
start with FILE when comparing directories
diff -S ...
--from-file
compare FILE1 to all operands; FILE1 can be a directory
diff --from-file ...
--to-file
compare all operands to FILE2; FILE2 can be a directory
diff --to-file ...
-i
ignore case differences in file contents
diff -i ...
-E
ignore changes due to tab expansion
diff -E ...
-Z
ignore white space at line end
diff -Z ...
-b
ignore changes in the amount of white space
diff -b ...
-w
ignore all white space
diff -w ...
-B
ignore changes where lines are all blank
diff -B ...
-I
ignore changes where all lines match RE
diff -I ...
-a
treat all files as text
diff -a ...
--strip-trailing-cr
strip trailing carriage return on input
diff --strip-trailing-cr ...
-D
output merged file with '#ifdef NAME' diffs
diff -D ...
--GTYPE-group-format
format GTYPE input groups with GFMT
diff --GTYPE-group-format ...
--line-format
format all input lines with LFMT
diff --line-format ...
--LTYPE-line-format
format LTYPE input lines with LFMTThese format options provide fine-grained control over the outputof diff, generalizing -D/--ifdef.LTYPE is 'old', 'new', or 'unchanged'.GTYPE is LTYPE or 'changed'.GFMT (only) may contain:%< lines from FILE1%> lines from FILE2%= lines common to FILE1 and FILE2%[-][WIDTH][.[PREC]]{doxX}LETTERprintf-style spec for LETTERLETTERs are as follows for new group, lower case for old group:F first line numberL last line numberN number of lines = L-F+1E F-1M L+1%(A=B?T:E)if A equals B then T else ELFMT (only) may contain:%L contents of line%l contents of line, excluding any trailing newline%[-][WIDTH][.[PREC]]{doxX}nprintf-style spec for input line numberBoth GFMT and LFMT may contain:%% %%c'C' the single character C%c'\OOO'the character with octal code OOOC the character C (other characters represent themselves)
diff --LTYPE-line-format ...
-d
try hard to find a smaller set of changes
diff -d ...
--horizon-lines
keep NUM lines of the common prefix and suffix
diff --horizon-lines ...
--speed-large-files
assume large files and many scattered small changes
diff --speed-large-files ...
--color[
colorize the output; WHEN can be 'never', 'always', or 'auto' (the default)
diff --color[ ...
--palette
the colors to use when --color is active; PALETTE is a colon-separated list of terminfo capabilities
diff --palette ...
--help
display this help and exit
diff --help ...
-v
output version information and exitFILES are 'FILE1 FILE2' or 'DIR1 DIR2' or 'DIR FILE' or 'FILE DIR'. If --from-file or --to-file is given, there are no restrictionson FILE(s). If a FILE is '-', read standard input. Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.AUTHORWritten by Paul Eggert, Mike Haertel, David Hayes, Richard Stallman, and Len Tower.REPORTING BUGSReport bugs to: bug-diffutils@gnu.orgGNU diffutils home page: <http://www.gnu.org/software/diffutils/>General help using GNU software: <http://www.gnu.org/gethelp/>COPYRIGHTCopyright © 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
diff -v ...