version 1.4, 2003/06/25 16:10:05 |
version 1.5, 2003/06/25 18:52:46 |
|
|
.\" |
.\" |
.Dd June 30, 1993 |
.Dd June 30, 1993 |
.Dt DIFF 1 |
.Dt DIFF 1 |
.Os BSD 4 |
.Os |
.Sh NAME |
.Sh NAME |
.Nm diff |
.Nm diff |
.Nd differential file and directory comparator |
.Nd differential file and directory comparator |
.Sh SYNOPSIS |
.Sh SYNOPSIS |
.Nm diff |
.Nm diff |
.Op Fl cefhn |
.Op Fl cefhn |
.Op Fl biwt |
.Op Fl bitw |
.Ar file1 file2 |
.Ar file1 file2 |
.Nm diff |
.Nm diff |
.Op Fl D Ns Ar string |
.Op Fl D Ns Ar string |
|
|
.Op Fl r |
.Op Fl r |
.Op Fl s |
.Op Fl s |
.Op Fl cefhn |
.Op Fl cefhn |
.Op Fl biwt |
.Op Fl bitw |
.Op Fl S Ns Ar name |
.Op Fl S Ns Ar name |
.Ar dir1 dir2 |
.Ar dir1 dir2 |
.Sh DESCRIPTION |
.Sh DESCRIPTION |
The |
The |
.Nm diff |
.Nm |
utility compares the contents of |
utility compares the contents of |
.Ar file1 |
.Ar file1 |
and |
and |
|
|
Output options (mutually exclusive): |
Output options (mutually exclusive): |
.Bl -tag -width Ds |
.Bl -tag -width Ds |
.It Fl c |
.It Fl c |
produces a diff with lines of context. |
Produces a diff with lines of context. |
The default is to present 3 lines of context and may be changed, e.g., to 10, by |
The default is to present 3 lines of context and may be changed, e.g., to 10, |
|
by |
.Fl c10 . |
.Fl c10 . |
With |
With |
.Fl c |
.Fl c |
|
|
by a line with a dozen *'s. |
by a line with a dozen *'s. |
The lines removed from |
The lines removed from |
.Ar file1 |
.Ar file1 |
are marked with `\(mi '; those added to |
are marked with |
|
.Sq \-\ \& ; |
|
those added to |
.Ar file2 |
.Ar file2 |
are marked `+ '. Lines which are changed from one |
are marked |
file to the other are marked in both files with `! '. |
.Sq \+\ \& . |
Changes which lie within <context> lines of each other are grouped |
Lines which are changed from one file to the other are marked in |
together on output. (This is a change from the previous ``diff -c'' |
both files with |
|
.Sq !\ \& . |
|
Changes which lie within |
|
.Aq context |
|
lines of each other are grouped together on output. |
|
(This is a change from the previous |
|
.Dq diff -c |
but the resulting output is usually much easier to interpret.) |
but the resulting output is usually much easier to interpret.) |
.It Fl e |
.It Fl e |
produces output in a form suitable as input for the editor utility, |
Produces output in a form suitable as input for the editor utility, |
.Xr ed 1 , |
.Xr ed 1 , |
which can then be used to convert file1 into file2. |
which can then be used to convert file1 into file2. |
.Pp |
.Pp |
Extra commands are added to the output when comparing directories with |
Extra commands are added to the output when comparing directories with |
.Fl e , |
.Fl e , |
so that the result is a |
so that the result is a |
.Xr sh 1 |
.Xr sh 1 |
script for converting text files which are common to the two directories |
script for converting text files which are common to the two directories |
from their state in |
from their state in |
.Ar dir1 |
.Ar dir1 |
to their state in |
to their state in |
.Ar dir2 . |
.Ar dir2 . |
.It Fl f |
.It Fl f |
identical output to that of the |
Identical output to that of the |
.Fl e |
.Fl e |
flag, but in reverse order. It cannot |
flag, but in reverse order. |
be digested by |
It cannot be digested by |
.Xr ed 1 . |
.Xr ed 1 . |
.It Fl h |
.It Fl h |
Invokes an alternate algorithm which can handle files of very long lengths. |
Invokes an alternate algorithm which can handle files of very long lengths. |
There is a trade off. The algorithm can only deal with changes which are |
There is a trade off. |
clearly delimited and brief. Long sections of changes and overlaps will |
The algorithm can only deal with changes which are clearly delimited and brief. |
confuse it. |
Long sections of changes and overlaps will confuse it. |
.It Fl n |
.It Fl n |
produces a script similar to that of |
Produces a script similar to that of |
.Fl e , |
.Fl e , |
but in the opposite order and with a count of changed lines on each |
but in the opposite order and with a count of changed lines on each |
insert or delete command. This is the form used by |
insert or delete command. |
.Xr rcsdiff 1 . |
This is the form used by |
|
.Xr rcsdiff 1 . |
.It Fl D Ns Ar string |
.It Fl D Ns Ar string |
creates a merged version of |
Creates a merged version of |
.Ar file1 |
.Ar file1 |
and |
and |
.Ar file2 |
.Ar file2 |
on the standard output, with C preprocessor controls included so that |
on the standard output, with C preprocessor controls included so that |
a compilation of the result without defining |
a compilation of the result without defining |
.Ar string |
.Ar string |
is equivalent |
is equivalent to compiling |
to compiling |
|
.Ar file1 , |
.Ar file1 , |
while defining |
while defining |
.Ar string |
.Ar string |
|
|
Comparison options: |
Comparison options: |
.Bl -tag -width Ds |
.Bl -tag -width Ds |
.It Fl b |
.It Fl b |
causes trailing blanks (spaces and tabs) to be ignored, and other |
Causes trailing blanks (spaces and tabs) to be ignored, and other |
strings of blanks to compare equal. |
strings of blanks to compare equal. |
.It Fl i |
.It Fl i |
ignores the case of letters. E.g., ``A'' will compare equal to ``a''. |
Ignores the case of letters. |
|
E.g., |
|
.Dq A |
|
will compare equal to |
|
.Dq a . |
.It Fl t |
.It Fl t |
will expand tabs in output lines. Normal or |
Will expand tabs in output lines. |
|
Normal or |
.Fl c |
.Fl c |
output adds character(s) to the front of each line which may screw up |
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 |
the indentation of the original source lines and make the output listing |
difficult to interpret. This option will preserve the original source's |
difficult to interpret. |
indentation. |
This option will preserve the original source's indentation. |
.It Fl w |
.It Fl w |
is similar to |
Is similar to |
.Fl b |
.Fl b |
but causes whitespace (blanks and tabs) to be totally ignored. E.g., |
but causes whitespace (blanks and tabs) to be totally ignored. |
``if\ (\ a\ ==\ b\ )'' will compare equal to ``if(a==b)''. |
E.g., |
|
.Dq if (\ \&a == b \&) |
|
will compare equal to |
|
.Dq if(a==b) . |
.El |
.El |
.Pp |
.Pp |
Directory comparison options: |
Directory comparison options: |
.Bl -tag -width Ds |
.Bl -tag -width Ds |
.It Fl l |
.It Fl l |
long output format; each text file |
Long output format; each text file |
.Nm diff Ns \'d |
.Nm diff Ns \'d |
is piped through |
is piped through |
.Xr pr 1 |
.Xr pr 1 |
to paginate it, |
to paginate it; |
other differences are remembered and summarized |
other differences are remembered and summarized |
after all text file differences are reported. |
after all text file differences are reported. |
.It Fl r |
.It Fl r |
causes application of |
Causes application of |
.Nm diff |
.Nm |
recursively to common subdirectories encountered. |
recursively to common subdirectories encountered. |
.It Fl s |
.It Fl s |
causes |
Causes |
.Nm diff |
.Nm |
to report files which are the same, which are otherwise not mentioned. |
to report files which are the same, which are otherwise not mentioned. |
.It Fl S Ns Ar name |
.It Fl S Ns Ar name |
re-starts a directory |
Re-starts a directory |
.Nm diff |
.Nm |
in the middle beginning with file |
in the middle, beginning with file |
.Ar name . |
.Ar name . |
.El |
.El |
.Pp |
.Pp |
If both arguments are directories, |
If both arguments are directories, |
.Nm diff |
.Nm |
sorts the contents of the directories by name, and then runs the |
sorts the contents of the directories by name, and then runs the |
regular file |
regular file |
.Nm diff |
.Nm |
algorithm, producing a change list, |
algorithm, producing a change list, |
on text files which are different. |
on text files which are different. |
Binary files which differ, |
Binary files which differ, |
|
|
and |
and |
.Ar file2 |
.Ar file2 |
is a directory, |
is a directory, |
.Nm diff |
.Nm |
is applied to the non-directory file and the file contained in |
is applied to the non-directory file and the file contained in |
the directory file with a filename that is the same as the |
the directory file with a filename that is the same as the |
last component of the non-directory file. |
last component of the non-directory file. |
|
|
.Fl c , |
.Fl c , |
or |
or |
.Fl n |
.Fl n |
.\" -C |
.\" -C |
options) |
options) |
output contains lines of these forms, where |
output contains lines of these forms, where |
.Va XX , YY , ZZ , QQ |
.Va XX , YY , ZZ , QQ |
|
|
At line |
At line |
.Va XX |
.Va XX |
delete |
delete |
the line. The value |
the line. |
|
The value |
.Va YY |
.Va YY |
tells to which line the change |
tells to which line the change would bring |
would bring |
|
.Ar file1 |
.Ar file1 |
in line with |
in line with |
.Ar file1 . |
.Ar file1 . |
|
|
to the line |
to the line |
.Va YY |
.Va YY |
in |
in |
.Ar file2. |
.Ar file2 . |
.It Li XX,YY Ns Ic c Ns Li ZZ |
.It Li XX,YY Ns Ic c Ns Li ZZ |
Replace the range of specified lines with the line |
Replace the range of specified lines with the line |
.Va ZZ . |
.Va ZZ . |
|
|
If the environment variable |
If the environment variable |
.Ev TMPDIR |
.Ev TMPDIR |
exists, |
exists, |
.Nm diff |
.Nm |
will use the directory specified by |
will use the directory specified by |
.Ev TMPDIR |
.Ev TMPDIR |
as the temporary directory. |
as the temporary directory. |
|
|
Alternate algorithm version (used by option |
Alternate algorithm version (used by option |
.Fl h ) . |
.Fl h ) . |
.It Pa /usr/bin/diff |
.It Pa /usr/bin/diff |
for directory diffs |
For directory diffs. |
.It Pa /usr/bin/pr |
.It Pa /usr/bin/pr |
used by the |
Used by the |
.Fl l |
.Fl l |
option. |
option. |
.El |
.El |
.Sh SEE ALSO |
|
.Xr cmp 1 , |
|
.Xr cc 1 , |
|
.Xr comm 1 , |
|
.Xr ed 1 , |
|
.Xr diff3 1 |
|
.br |
|
.ne 1i |
|
.Sh DIAGNOSTICS |
.Sh DIAGNOSTICS |
The |
The |
.Nm diff |
.Nm |
utility exits with one of the following values: |
utility exits with one of the following values: |
.Pp |
.Pp |
.Bl -tag -width Ds -compact -offset indent |
.Bl -tag -width Ds -compact -offset indent |
|
|
No differences were found. |
No differences were found. |
.It \&1 |
.It \&1 |
Differences were found. |
Differences were found. |
.It "\&>\&1" |
.It \*[Gt]\&1 |
An error occurred. |
An error occurred. |
.El |
.El |
|
.Sh SEE ALSO |
|
.Xr cc 1 , |
|
.Xr cmp 1 , |
|
.Xr comm 1 , |
|
.Xr diff3 1 , |
|
.Xr ed 1 |
|
.Sh HISTORY |
|
A |
|
.Nm |
|
command appeared in |
|
.At v6 . |
.Sh BUGS |
.Sh BUGS |
The |
The |
.Fl f |
.Fl f |
|
|
or |
or |
.Fl i |
.Fl i |
options specified, |
options specified, |
.Nm diff |
.Nm |
first compares the files ala |
first compares the files ala |
.Ar cmp , |
.Xr cmp 1 , |
and then decides to run the |
and then decides to run the |
.Nm diff |
.Nm |
algorithm if they are not equal. |
algorithm if they are not equal. |
This may cause a small amount of spurious output if the files |
This may cause a small amount of spurious output if the files |
then turn out to be identical because the only differences are |
then turn out to be identical because the only differences are |
insignificant white space or case differences. |
insignificant whitespace or case differences. |
.Sh HISTORY |
|
A |
|
.Nm |
|
command appeared in |
|
.At v6 . |
|