2017-03-11 05:01:29 +00:00
|
|
|
.\" $OpenBSD: diff.1,v 1.47 2015/11/24 19:35:41 jmc Exp $
|
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1980, 1990, 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)diff.1 8.1 (Berkeley) 6/30/93
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2020-06-19 06:48:16 +00:00
|
|
|
.Dd June 19, 2020
|
2017-03-11 05:01:29 +00:00
|
|
|
.Dt DIFF 1
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm diff
|
|
|
|
.Nd differential file and directory comparator
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm diff
|
2018-08-19 03:57:20 +00:00
|
|
|
.Op Fl aBbdipTtw
|
2017-03-11 05:01:29 +00:00
|
|
|
.Oo
|
|
|
|
.Fl c | e | f |
|
2020-02-07 10:17:13 +00:00
|
|
|
.Fl n | q | u | y
|
2017-03-11 05:01:29 +00:00
|
|
|
.Oc
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -brief
|
2021-09-05 00:10:41 +00:00
|
|
|
.Op Fl -color Ns = Ns Ar when
|
2017-04-20 14:22:33 +00:00
|
|
|
.Op Fl -changed-group-format Ar GFMT
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ed
|
|
|
|
.Op Fl -expand-tabs
|
|
|
|
.Op Fl -forward-ed
|
|
|
|
.Op Fl -ignore-all-space
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -ignore-case
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ignore-space-change
|
|
|
|
.Op Fl -initial-tab
|
|
|
|
.Op Fl -minimal
|
2017-03-22 18:13:14 +00:00
|
|
|
.Op Fl -no-ignore-file-name-case
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -normal
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -rcs
|
|
|
|
.Op Fl -show-c-function
|
|
|
|
.Op Fl -starting-file
|
2017-04-08 08:46:02 +00:00
|
|
|
.Op Fl -speed-large-files
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -strip-trailing-cr
|
2020-02-13 20:23:55 +00:00
|
|
|
.Op Fl -tabsize Ar number
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -text
|
|
|
|
.Op Fl -unified
|
|
|
|
.Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
|
2021-09-05 14:54:07 +00:00
|
|
|
.Op Fl F Ar pattern | Fl -show-function-line Ar pattern
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl L Ar label | Fl -label Ar label
|
2017-03-11 05:01:29 +00:00
|
|
|
.Ar file1 file2
|
|
|
|
.Nm diff
|
2018-08-19 03:57:20 +00:00
|
|
|
.Op Fl aBbdilpTtw
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
|
2021-09-05 14:54:07 +00:00
|
|
|
.Op Fl F Ar pattern | Fl -show-function-line Ar pattern
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl L Ar label | Fl -label Ar label
|
|
|
|
.Op Fl -brief
|
2021-09-05 00:10:41 +00:00
|
|
|
.Op Fl -color Ns = Ns Ar when
|
2017-04-20 14:22:33 +00:00
|
|
|
.Op Fl -changed-group-format Ar GFMT
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ed
|
|
|
|
.Op Fl -expand-tabs
|
|
|
|
.Op Fl -forward-ed
|
|
|
|
.Op Fl -ignore-all-space
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -ignore-case
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ignore-space-change
|
|
|
|
.Op Fl -initial-tab
|
|
|
|
.Op Fl -minimal
|
2017-03-22 18:13:14 +00:00
|
|
|
.Op Fl -no-ignore-file-name-case
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -normal
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -paginate
|
|
|
|
.Op Fl -rcs
|
|
|
|
.Op Fl -show-c-function
|
2017-04-08 08:46:02 +00:00
|
|
|
.Op Fl -speed-large-files
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -starting-file
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -strip-trailing-cr
|
2020-02-13 20:23:55 +00:00
|
|
|
.Op Fl -tabsize Ar number
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -text
|
|
|
|
.Fl C Ar number | -context Ar number
|
2017-03-11 05:01:29 +00:00
|
|
|
.Ar file1 file2
|
|
|
|
.Nm diff
|
2018-08-19 03:57:20 +00:00
|
|
|
.Op Fl aBbdiltw
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
|
|
|
|
.Op Fl -brief
|
2021-09-05 00:10:41 +00:00
|
|
|
.Op Fl -color Ns = Ns Ar when
|
2017-04-20 14:22:33 +00:00
|
|
|
.Op Fl -changed-group-format Ar GFMT
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ed
|
|
|
|
.Op Fl -expand-tabs
|
|
|
|
.Op Fl -forward-ed
|
|
|
|
.Op Fl -ignore-all-space
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -ignore-case
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ignore-space-change
|
|
|
|
.Op Fl -initial-tab
|
|
|
|
.Op Fl -minimal
|
2017-03-22 18:13:14 +00:00
|
|
|
.Op Fl -no-ignore-file-name-case
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -normal
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -paginate
|
|
|
|
.Op Fl -rcs
|
|
|
|
.Op Fl -show-c-function
|
2017-04-08 08:46:02 +00:00
|
|
|
.Op Fl -speed-large-files
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -starting-file
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -strip-trailing-cr
|
2020-02-13 20:23:55 +00:00
|
|
|
.Op Fl -tabsize Ar number
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -text
|
|
|
|
.Fl D Ar string | Fl -ifdef Ar string
|
2017-03-11 05:01:29 +00:00
|
|
|
.Ar file1 file2
|
|
|
|
.Nm diff
|
2018-08-19 03:57:20 +00:00
|
|
|
.Op Fl aBbdilpTtw
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
|
2021-09-05 14:54:07 +00:00
|
|
|
.Op Fl F Ar pattern | Fl -show-function-line Ar pattern
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl L Ar label | Fl -label Ar label
|
|
|
|
.Op Fl -brief
|
2021-09-05 00:10:41 +00:00
|
|
|
.Op Fl -color Ns = Ns Ar when
|
2017-04-20 14:22:33 +00:00
|
|
|
.Op Fl -changed-group-format Ar GFMT
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ed
|
|
|
|
.Op Fl -expand-tabs
|
|
|
|
.Op Fl -forward-ed
|
|
|
|
.Op Fl -ignore-all-space
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -ignore-case
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ignore-space-change
|
|
|
|
.Op Fl -initial-tab
|
|
|
|
.Op Fl -minimal
|
2017-03-22 18:13:14 +00:00
|
|
|
.Op Fl -no-ignore-file-name-case
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -normal
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -paginate
|
|
|
|
.Op Fl -rcs
|
|
|
|
.Op Fl -show-c-function
|
2017-04-08 08:46:02 +00:00
|
|
|
.Op Fl -speed-large-files
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -starting-file
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -strip-trailing-cr
|
2020-02-13 20:23:55 +00:00
|
|
|
.Op Fl -tabsize Ar number
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -text
|
|
|
|
.Fl U Ar number | Fl -unified Ar number
|
2017-03-11 05:01:29 +00:00
|
|
|
.Ar file1 file2
|
|
|
|
.Nm diff
|
2018-08-19 03:57:20 +00:00
|
|
|
.Op Fl aBbdilNPprsTtw
|
2017-03-11 05:01:29 +00:00
|
|
|
.Oo
|
|
|
|
.Fl c | e | f |
|
|
|
|
.Fl n | q | u
|
|
|
|
.Oc
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -brief
|
2021-09-05 00:10:41 +00:00
|
|
|
.Op Fl -color Ns = Ns Ar when
|
2017-04-20 14:22:33 +00:00
|
|
|
.Op Fl -changed-group-format Ar GFMT
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -context
|
|
|
|
.Op Fl -ed
|
|
|
|
.Op Fl -expand-tabs
|
|
|
|
.Op Fl -forward-ed
|
|
|
|
.Op Fl -ignore-all-space
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -ignore-case
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -ignore-space-change
|
|
|
|
.Op Fl -initial-tab
|
|
|
|
.Op Fl -minimal
|
|
|
|
.Op Fl -new-file
|
2017-03-22 18:13:14 +00:00
|
|
|
.Op Fl -no-ignore-file-name-case
|
2017-03-11 05:01:29 +00:00
|
|
|
.Op Fl -normal
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -paginate
|
|
|
|
.Op Fl -rcs
|
|
|
|
.Op Fl -recursive
|
|
|
|
.Op Fl -report-identical-files
|
|
|
|
.Op Fl -show-c-function
|
2017-04-08 08:46:02 +00:00
|
|
|
.Op Fl -speed-large-files
|
2017-03-19 21:49:15 +00:00
|
|
|
.Op Fl -strip-trailing-cr
|
2020-02-13 20:23:55 +00:00
|
|
|
.Op Fl -tabsize Ar number
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl -text
|
|
|
|
.Op Fl -unidirectional-new-file
|
|
|
|
.Op Fl -unified
|
|
|
|
.Op Fl I Ar pattern | Fl -ignore-matching-lines Ar pattern
|
2021-09-05 14:54:07 +00:00
|
|
|
.Op Fl F Ar pattern | Fl -show-function-line Ar pattern
|
2017-03-11 05:01:29 +00:00
|
|
|
.Bk -words
|
2017-03-23 04:35:52 +00:00
|
|
|
.Op Fl L Ar label | Fl -label Ar label
|
|
|
|
.Op Fl S Ar name | Fl -starting-file Ar name
|
|
|
|
.Op Fl X Ar file | Fl -exclude-from Ar file
|
|
|
|
.Op Fl x Ar pattern | Fl -exclude Ar pattern
|
2017-03-11 05:01:29 +00:00
|
|
|
.Ek
|
|
|
|
.Ar dir1 dir2
|
2020-02-07 10:17:13 +00:00
|
|
|
.Nm diff
|
|
|
|
.Op Fl aBbditwW
|
2021-09-05 00:10:41 +00:00
|
|
|
.Op Fl -color Ns = Ns Ar when
|
2020-02-12 20:06:41 +00:00
|
|
|
.Op Fl -expand-tabs
|
|
|
|
.Op Fl -ignore-all-blanks
|
|
|
|
.Op Fl -ignore-blank-lines
|
|
|
|
.Op Fl -ignore-case
|
|
|
|
.Op Fl -minimal
|
|
|
|
.Op Fl -no-ignore-file-name-case
|
|
|
|
.Op Fl -strip-trailing-cr
|
|
|
|
.Op Fl -suppress-common-lines
|
2020-02-13 20:23:55 +00:00
|
|
|
.Op Fl -tabsize Ar number
|
2020-02-12 20:06:41 +00:00
|
|
|
.Op Fl -text
|
|
|
|
.Op Fl -width
|
2020-02-07 10:17:13 +00:00
|
|
|
.Fl y | Fl -side-by-side
|
|
|
|
.Ar file1 file2
|
2017-03-11 05:01:29 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility compares the contents of
|
|
|
|
.Ar file1
|
|
|
|
and
|
|
|
|
.Ar file2
|
|
|
|
and writes to the standard output the list of changes necessary to
|
|
|
|
convert one file into the other.
|
|
|
|
No output is produced if the files are identical.
|
|
|
|
.Pp
|
|
|
|
Output options (mutually exclusive):
|
|
|
|
.Bl -tag -width Ds
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl C Ar number Fl -context Ar number
|
2017-03-11 05:01:29 +00:00
|
|
|
Like
|
|
|
|
.Fl c
|
|
|
|
but produces a diff with
|
|
|
|
.Ar number
|
|
|
|
lines of context.
|
|
|
|
.It Fl c
|
|
|
|
Produces a diff with 3 lines of context.
|
|
|
|
With
|
|
|
|
.Fl c
|
|
|
|
the output format is modified slightly:
|
|
|
|
the output begins with identification of the files involved and
|
|
|
|
their creation dates and then each change is separated
|
|
|
|
by a line with fifteen
|
|
|
|
.Li * Ns 's .
|
|
|
|
The lines removed from
|
|
|
|
.Ar file1
|
|
|
|
are marked with
|
|
|
|
.Sq \&-\ \& ;
|
|
|
|
those added to
|
|
|
|
.Ar file2
|
|
|
|
are marked
|
2020-02-07 12:26:38 +00:00
|
|
|
.Sq +\ \& .
|
2017-03-11 05:01:29 +00:00
|
|
|
Lines which are changed from one file to the other are marked in
|
|
|
|
both files with
|
|
|
|
.Sq !\ \& .
|
|
|
|
Changes which lie within 3 lines of each other are grouped together on
|
|
|
|
output.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl D Ar string Fl -ifdef Ar string
|
2017-03-11 05:01:29 +00:00
|
|
|
Creates a merged version of
|
|
|
|
.Ar file1
|
|
|
|
and
|
|
|
|
.Ar file2
|
|
|
|
on the standard output, with C preprocessor controls included so that
|
|
|
|
a compilation of the result without defining
|
|
|
|
.Ar string
|
|
|
|
is equivalent to compiling
|
|
|
|
.Ar file1 ,
|
|
|
|
while defining
|
|
|
|
.Ar string
|
|
|
|
will yield
|
|
|
|
.Ar file2 .
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl e -ed
|
2017-03-11 05:01:29 +00:00
|
|
|
Produces output in a form suitable as input for the editor utility,
|
|
|
|
.Xr ed 1 ,
|
|
|
|
which can then be used to convert file1 into file2.
|
|
|
|
.Pp
|
|
|
|
Extra commands are added to the output when comparing directories with
|
|
|
|
.Fl e ,
|
|
|
|
so that the result is a
|
|
|
|
.Xr sh 1
|
|
|
|
script for converting text files which are common to the two directories
|
|
|
|
from their state in
|
|
|
|
.Ar dir1
|
|
|
|
to their state in
|
|
|
|
.Ar dir2 .
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl f -forward-ed
|
2017-03-11 05:01:29 +00:00
|
|
|
Identical output to that of the
|
|
|
|
.Fl e
|
|
|
|
flag, but in reverse order.
|
|
|
|
It cannot be digested by
|
|
|
|
.Xr ed 1 .
|
|
|
|
.It Fl n
|
|
|
|
Produces a script similar to that of
|
|
|
|
.Fl e ,
|
|
|
|
but in the opposite order and with a count of changed lines on each
|
|
|
|
insert or delete command.
|
2020-06-19 06:48:16 +00:00
|
|
|
This is the form used by rcsdiff.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl q -brief
|
2017-03-11 05:01:29 +00:00
|
|
|
Just print a line when the files differ.
|
|
|
|
Does not output a list of changes.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl U Ar number Fl -unified Ar number
|
2017-03-11 05:01:29 +00:00
|
|
|
Like
|
|
|
|
.Fl u
|
|
|
|
but produces a diff with
|
|
|
|
.Ar number
|
|
|
|
lines of context.
|
|
|
|
.It Fl u
|
|
|
|
Produces a
|
|
|
|
.Em unified
|
|
|
|
diff with 3 lines of context.
|
|
|
|
A unified diff is similar to the context diff produced by the
|
|
|
|
.Fl c
|
|
|
|
option.
|
|
|
|
However, unlike with
|
|
|
|
.Fl c ,
|
|
|
|
all lines to be changed (added and/or removed) are present in
|
|
|
|
a single section.
|
2020-02-07 10:17:13 +00:00
|
|
|
.It Fl y Fl -side-by-side
|
2020-02-07 12:26:38 +00:00
|
|
|
Output in two columns with a marker between them.
|
|
|
|
The marker can be one
|
2020-02-07 10:17:13 +00:00
|
|
|
of the following:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width Ds -offset indent -compact
|
2020-02-07 12:26:38 +00:00
|
|
|
.It space
|
2020-02-07 10:17:13 +00:00
|
|
|
Corresponding lines are identical.
|
|
|
|
.It '|'
|
|
|
|
Corresponding lines are different.
|
|
|
|
.It '<'
|
|
|
|
Files differ and only the first file contains the line.
|
|
|
|
.It '>'
|
|
|
|
Files differ and only the second file contains the line.
|
|
|
|
.El
|
2017-03-11 05:01:29 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Comparison options:
|
|
|
|
.Bl -tag -width Ds
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl a -text
|
2020-02-07 12:26:38 +00:00
|
|
|
Treat all files as ASCII text.
|
2017-03-11 05:01:29 +00:00
|
|
|
Normally
|
|
|
|
.Nm
|
|
|
|
will simply print
|
|
|
|
.Dq Binary files ... differ
|
|
|
|
if files contain binary characters.
|
|
|
|
Use of this option forces
|
|
|
|
.Nm
|
|
|
|
to produce a diff.
|
2018-08-19 03:57:20 +00:00
|
|
|
.It Fl B Fl -ignore-blank-lines
|
|
|
|
Causes chunks that include only blank lines to be ignored.
|
2020-06-01 09:15:15 +00:00
|
|
|
.It Fl b -ignore-space-change
|
2017-03-11 05:01:29 +00:00
|
|
|
Causes trailing blanks (spaces and tabs) to be ignored, and other
|
|
|
|
strings of blanks to compare equal.
|
2021-09-05 00:10:41 +00:00
|
|
|
.It Fl -color= Ns Oo Ar when Oc
|
|
|
|
Color the additions green, and removals red, or the value in the
|
|
|
|
.Ev DIFFCOLORS
|
|
|
|
environment variable.
|
|
|
|
The possible values of
|
|
|
|
.Ar when
|
|
|
|
are
|
|
|
|
.Dq Cm never ,
|
|
|
|
.Dq Cm always
|
|
|
|
and
|
|
|
|
.Dq Cm auto .
|
|
|
|
.Cm auto
|
|
|
|
will use color if the output is a tty and the
|
|
|
|
.Ev COLORTERM
|
|
|
|
environment variable is set to a non-empty string.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl d -minimal
|
2017-03-11 05:01:29 +00:00
|
|
|
Try very hard to produce a diff as small as possible.
|
|
|
|
This may consume a lot of processing power and memory when processing
|
|
|
|
large files with many changes.
|
2021-09-05 14:54:07 +00:00
|
|
|
.It Fl F Ar pattern, Fl -show-function-line Ar pattern
|
|
|
|
Like
|
|
|
|
.Fl p,
|
|
|
|
but display the last line that matches provided pattern.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl I Ar pattern Fl -ignore-matching-lines Ar pattern
|
2017-03-11 05:01:29 +00:00
|
|
|
Ignores changes, insertions, and deletions whose lines match the
|
|
|
|
extended regular expression
|
|
|
|
.Ar pattern .
|
|
|
|
Multiple
|
|
|
|
.Fl I
|
|
|
|
patterns may be specified.
|
|
|
|
All lines in the change must match some pattern for the change to be
|
|
|
|
ignored.
|
|
|
|
See
|
|
|
|
.Xr re_format 7
|
|
|
|
for more information on regular expression patterns.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl i -ignore-case
|
2017-03-11 05:01:29 +00:00
|
|
|
Ignores the case of letters.
|
|
|
|
E.g.,
|
|
|
|
.Dq A
|
|
|
|
will compare equal to
|
|
|
|
.Dq a .
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl l -paginate
|
2017-03-11 05:01:29 +00:00
|
|
|
Pass the output through
|
|
|
|
.Xr pr 1
|
|
|
|
to paginate it.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl L Ar label Fl -label Ar label
|
2017-03-11 05:01:29 +00:00
|
|
|
Print
|
|
|
|
.Ar label
|
|
|
|
instead of the first (and second, if this option is specified twice)
|
|
|
|
file name and time in the context or unified diff header.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl p -show-c-function
|
2017-03-11 05:01:29 +00:00
|
|
|
With unified and context diffs, show with each change
|
|
|
|
the first 40 characters of the last line before the context beginning
|
|
|
|
with a letter, an underscore or a dollar sign.
|
|
|
|
For C source code following standard layout conventions, this will
|
|
|
|
show the prototype of the function the change applies to.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl T -initial-tab
|
2017-03-11 05:01:29 +00:00
|
|
|
Print a tab rather than a space before the rest of the line for the
|
|
|
|
normal, context or unified output formats.
|
|
|
|
This makes the alignment of tabs in the line consistent.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl t -expand-tabs
|
2017-03-11 05:01:29 +00:00
|
|
|
Will expand tabs in output lines.
|
|
|
|
Normal or
|
|
|
|
.Fl c
|
|
|
|
output adds character(s) to the front of each line which may screw up
|
|
|
|
the indentation of the original source lines and make the output listing
|
|
|
|
difficult to interpret.
|
|
|
|
This option will preserve the original source's indentation.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl w -ignore-all-blanks
|
2017-03-11 05:01:29 +00:00
|
|
|
Is similar to
|
2017-04-20 19:05:43 +00:00
|
|
|
.Fl b -ignore-space-change
|
2017-03-11 05:01:29 +00:00
|
|
|
but causes whitespace (blanks and tabs) to be totally ignored.
|
|
|
|
E.g.,
|
|
|
|
.Dq if (\ \&a == b \&)
|
|
|
|
will compare equal to
|
|
|
|
.Dq if(a==b) .
|
2020-02-07 10:17:13 +00:00
|
|
|
.It Fl W Ar number Fl -width Ar number
|
|
|
|
Output at most
|
|
|
|
.Ar number
|
2020-02-07 12:26:38 +00:00
|
|
|
columns when using side by side format.
|
|
|
|
The default value is 130.
|
2017-04-20 14:22:33 +00:00
|
|
|
.It Fl -changed-group-format Ar GFMT
|
|
|
|
Format input groups in the provided
|
|
|
|
.Pp
|
|
|
|
the format is a string with special keywords:
|
|
|
|
.Bl -tag -width %<
|
|
|
|
.It %<
|
|
|
|
lines from FILE1
|
|
|
|
.It %<
|
|
|
|
lines from FILE2
|
|
|
|
.El
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl -ignore-file-name-case
|
|
|
|
ignore case when comparing file names
|
|
|
|
.It Fl -no-ignore-file-name-case
|
|
|
|
do not ignore case wen comparing file names (default)
|
|
|
|
.It Fl -normal
|
|
|
|
default diff output
|
|
|
|
.It Fl -speed-large-files
|
|
|
|
stub option for compatibility with GNU diff
|
|
|
|
.It Fl -strip-trailing-cr
|
|
|
|
strip carriage return on input files
|
2020-02-07 10:17:13 +00:00
|
|
|
.It Fl -suppress-common-lines
|
|
|
|
Do not output common lines when using the side by side format
|
|
|
|
.It Fl -tabsize Ar number
|
2017-04-20 19:05:43 +00:00
|
|
|
Number of spaces representing a tab (default 8)
|
2017-03-11 05:01:29 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Directory comparison options:
|
|
|
|
.Bl -tag -width Ds
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl N -new-file
|
2017-03-11 05:01:29 +00:00
|
|
|
If a file is found in only one directory, act as if it was found in the
|
|
|
|
other directory too but was of zero size.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl P -unidirectional-new-file
|
2017-03-11 05:01:29 +00:00
|
|
|
If a file is found only in
|
|
|
|
.Ar dir2 ,
|
|
|
|
act as if it was found in
|
|
|
|
.Ar dir1
|
|
|
|
too but was of zero size.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl r -recursive
|
2017-03-11 05:01:29 +00:00
|
|
|
Causes application of
|
|
|
|
.Nm
|
|
|
|
recursively to common subdirectories encountered.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl S Ar name Fl -starting-file Ar name
|
2017-03-11 05:01:29 +00:00
|
|
|
Re-starts a directory
|
|
|
|
.Nm
|
|
|
|
in the middle, beginning with file
|
|
|
|
.Ar name .
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl s -report-identical-files
|
2017-03-11 05:01:29 +00:00
|
|
|
Causes
|
|
|
|
.Nm
|
|
|
|
to report files which are the same, which are otherwise not mentioned.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl X Ar file Fl -exclude-from Ar file
|
2017-03-11 05:01:29 +00:00
|
|
|
Exclude files and subdirectories from comparison whose basenames match
|
|
|
|
lines in
|
|
|
|
.Ar file .
|
|
|
|
Multiple
|
|
|
|
.Fl X
|
|
|
|
options may be specified.
|
2017-04-20 19:05:43 +00:00
|
|
|
.It Fl x Ar pattern Fl -exclude Ar pattern
|
2017-03-11 05:01:29 +00:00
|
|
|
Exclude files and subdirectories from comparison whose basenames match
|
|
|
|
.Ar pattern .
|
|
|
|
Patterns are matched using shell-style globbing via
|
|
|
|
.Xr fnmatch 3 .
|
|
|
|
Multiple
|
|
|
|
.Fl x
|
|
|
|
options may be specified.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
If both arguments are directories,
|
|
|
|
.Nm
|
|
|
|
sorts the contents of the directories by name, and then runs the
|
|
|
|
regular file
|
|
|
|
.Nm
|
|
|
|
algorithm, producing a change list,
|
|
|
|
on text files which are different.
|
|
|
|
Binary files which differ,
|
|
|
|
common subdirectories, and files which appear in only one directory
|
|
|
|
are described as such.
|
|
|
|
In directory mode only regular files and directories are compared.
|
2020-02-07 12:26:38 +00:00
|
|
|
If a non-regular file such as a device special file or FIFO is encountered,
|
|
|
|
a diagnostic message is printed.
|
2017-03-11 05:01:29 +00:00
|
|
|
.Pp
|
|
|
|
If only one of
|
|
|
|
.Ar file1
|
|
|
|
and
|
|
|
|
.Ar file2
|
|
|
|
is a directory,
|
|
|
|
.Nm
|
|
|
|
is applied to the non-directory file and the file contained in
|
|
|
|
the directory file with a filename that is the same as the
|
|
|
|
last component of the non-directory file.
|
|
|
|
.Pp
|
|
|
|
If either
|
|
|
|
.Ar file1
|
|
|
|
or
|
|
|
|
.Ar file2
|
|
|
|
is
|
|
|
|
.Sq - ,
|
|
|
|
the standard input is
|
|
|
|
used in its place.
|
|
|
|
.Ss Output Style
|
|
|
|
The default (without
|
|
|
|
.Fl e ,
|
|
|
|
.Fl c ,
|
|
|
|
or
|
2017-04-20 19:05:43 +00:00
|
|
|
.Fl n -rcs
|
2017-03-11 05:01:29 +00:00
|
|
|
.\" -C
|
|
|
|
options)
|
|
|
|
output contains lines of these forms, where
|
|
|
|
.Va XX , YY , ZZ , QQ
|
|
|
|
are line numbers respective of file order.
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width "XX,YYcZZ,QQ" -compact
|
|
|
|
.It Li XX Ns Ic a Ns Li YY
|
|
|
|
At (the end of) line
|
|
|
|
.Va XX
|
|
|
|
of
|
|
|
|
.Ar file1 ,
|
|
|
|
append the contents
|
|
|
|
of line
|
|
|
|
.Va YY
|
|
|
|
of
|
|
|
|
.Ar file2
|
|
|
|
to make them equal.
|
|
|
|
.It Li XX Ns Ic a Ns Li YY,ZZ
|
|
|
|
Same as above, but append the range of lines,
|
|
|
|
.Va YY
|
|
|
|
through
|
|
|
|
.Va ZZ
|
|
|
|
of
|
|
|
|
.Ar file2
|
|
|
|
to line
|
|
|
|
.Va XX
|
|
|
|
of file1.
|
|
|
|
.It Li XX Ns Ic d Ns Li YY
|
|
|
|
At line
|
|
|
|
.Va XX
|
|
|
|
delete
|
|
|
|
the line.
|
|
|
|
The value
|
|
|
|
.Va YY
|
|
|
|
tells to which line the change would bring
|
|
|
|
.Ar file1
|
|
|
|
in line with
|
|
|
|
.Ar file2 .
|
|
|
|
.It Li XX,YY Ns Ic d Ns Li ZZ
|
|
|
|
Delete the range of lines
|
|
|
|
.Va XX
|
|
|
|
through
|
|
|
|
.Va YY
|
|
|
|
in
|
|
|
|
.Ar file1 .
|
|
|
|
.It Li XX Ns Ic c Ns Li YY
|
|
|
|
Change the line
|
|
|
|
.Va XX
|
|
|
|
in
|
|
|
|
.Ar file1
|
|
|
|
to the line
|
|
|
|
.Va YY
|
|
|
|
in
|
|
|
|
.Ar file2 .
|
|
|
|
.It Li XX,YY Ns Ic c Ns Li ZZ
|
|
|
|
Replace the range of specified lines with the line
|
|
|
|
.Va ZZ .
|
|
|
|
.It Li XX,YY Ns Ic c Ns Li ZZ,QQ
|
|
|
|
Replace the range
|
|
|
|
.Va XX , Ns Va YY
|
|
|
|
from
|
|
|
|
.Ar file1
|
|
|
|
with the range
|
|
|
|
.Va ZZ , Ns Va QQ
|
|
|
|
from
|
|
|
|
.Ar file2 .
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
These lines resemble
|
|
|
|
.Xr ed 1
|
|
|
|
subcommands to convert
|
|
|
|
.Ar file1
|
|
|
|
into
|
|
|
|
.Ar file2 .
|
|
|
|
The line numbers before the action letters pertain to
|
|
|
|
.Ar file1 ;
|
|
|
|
those after pertain to
|
|
|
|
.Ar file2 .
|
|
|
|
Thus, by exchanging
|
|
|
|
.Ic a
|
|
|
|
for
|
|
|
|
.Ic d
|
|
|
|
and reading the line in reverse order, one can also
|
|
|
|
determine how to convert
|
|
|
|
.Ar file2
|
|
|
|
into
|
|
|
|
.Ar file1 .
|
|
|
|
As in
|
|
|
|
.Xr ed 1 ,
|
|
|
|
identical
|
|
|
|
pairs (where num1 = num2) are abbreviated as a single
|
|
|
|
number.
|
2021-09-05 00:10:41 +00:00
|
|
|
.Sh ENVIRONMENT
|
|
|
|
.Bl -tag -width DIFFCOLORS
|
|
|
|
.It Ev DIFFCOLORS
|
|
|
|
The value of this variable is the form
|
|
|
|
.Ar add Ns : Ns Ar rm ,
|
|
|
|
where
|
|
|
|
.Ar add
|
|
|
|
is the ASCII escape sequence for additions and
|
|
|
|
.Ar rm
|
|
|
|
is the ASCII escape sequence for deletions.
|
|
|
|
If this is unset,
|
|
|
|
.Nm
|
|
|
|
uses green for additions and red for removals.
|
|
|
|
.El
|
2017-03-11 05:01:29 +00:00
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width /tmp/diff.XXXXXXXX -compact
|
2020-02-07 12:26:38 +00:00
|
|
|
.It Pa /tmp/diff.XXXXXXXX
|
2017-03-11 05:01:29 +00:00
|
|
|
Temporary file used when comparing a device or the standard input.
|
|
|
|
Note that the temporary file is unlinked as soon as it is created
|
|
|
|
so it will not show up in a directory listing.
|
|
|
|
.El
|
|
|
|
.Sh EXIT STATUS
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility exits with one of the following values:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width Ds -offset indent -compact
|
|
|
|
.It 0
|
|
|
|
No differences were found.
|
|
|
|
.It 1
|
|
|
|
Differences were found.
|
|
|
|
.It >1
|
|
|
|
An error occurred.
|
|
|
|
.El
|
2020-06-19 06:48:16 +00:00
|
|
|
.Sh EXAMPLES
|
|
|
|
Compare
|
|
|
|
.Pa old_dir
|
|
|
|
and
|
|
|
|
.Pa new_dir
|
|
|
|
recursively generating an unified diff and treating files found only in one
|
|
|
|
of those directories as new files:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ diff -ruN /path/to/old_dir /path/to/new_dir
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Same as above but excluding files matching the expressions
|
|
|
|
.Dq *.h
|
|
|
|
and
|
|
|
|
.Dq *.c :
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ diff -ruN -x '*.h' -x '*.c' /path/to/old_dir /path/to/new_dir
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Show a single line indicating if the files differ:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ diff -q /boot/loader.conf /boot/defaults/loader.conf
|
|
|
|
Files /boot/loader.conf and /boot/defaults/loader.conf differ
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Assuming a file named
|
|
|
|
.Pa example.txt
|
|
|
|
with the following contents:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
FreeBSD is an operating system
|
|
|
|
Linux is a kernel
|
|
|
|
OpenBSD is an operating system
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Compare stdin with
|
|
|
|
.Pa example.txt
|
|
|
|
excluding from the comparison those lines containing either
|
|
|
|
.Qq Linux
|
|
|
|
or
|
|
|
|
.Qq Open :
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ echo "FreeBSD is an operating system" | diff -q -I 'Linux|Open' example.txt -
|
|
|
|
.Ed
|
2017-03-11 05:01:29 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr cmp 1 ,
|
|
|
|
.Xr comm 1 ,
|
|
|
|
.Xr diff3 1 ,
|
|
|
|
.Xr ed 1 ,
|
|
|
|
.Xr patch 1 ,
|
2017-04-20 19:14:52 +00:00
|
|
|
.Xr pr 1 ,
|
2017-03-11 05:01:29 +00:00
|
|
|
.Xr sdiff 1
|
|
|
|
.Rs
|
|
|
|
.%A James W. Hunt
|
|
|
|
.%A M. Douglas McIlroy
|
|
|
|
.%T "An Algorithm for Differential File Comparison"
|
|
|
|
.%J Computing Science Technical Report
|
|
|
|
.%Q Bell Laboratories 41
|
|
|
|
.%D June 1976
|
|
|
|
.Re
|
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility is compliant with the
|
|
|
|
.St -p1003.1-2008
|
|
|
|
specification.
|
|
|
|
.Pp
|
|
|
|
The flags
|
2020-02-12 20:06:41 +00:00
|
|
|
.Op Fl aDdIiLlNnPpqSsTtwXxy
|
2017-03-11 05:01:29 +00:00
|
|
|
are extensions to that specification.
|
|
|
|
.Sh HISTORY
|
|
|
|
A
|
|
|
|
.Nm
|
|
|
|
command appeared in
|
|
|
|
.At v6 .
|