📄 diff.1
字号:
.\" 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. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. 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.\".Dd June 30, 1993.Dt DIFF 1.Os BSD 4.Sh NAME.Nm diff.Nd differential file and directory comparator.Sh SYNOPSIS.Nm diff.Op Fl cefhn.Op Fl biwt.Ar file1 file2.Nm diff.Op Fl D Ns Ar string.Op Fl biw.Ar file1 file2.Nm diff.Op Fl l.Op Fl r.Op Fl s.Op Fl cefhn.Op Fl biwt.Op Fl S Ns Ar name.Ar dir1 dir2.Sh DESCRIPTIONThe.Nm diffutility compares the contents of.Ar file1and.Ar file2and writes to the standard output the list of changes necessary toconvert one file into the other.No output is produced if the files are identical..PpOutput options (mutually exclusive):.Bl -tag -width Ds.It Fl cproduces a diff with lines of context.The default is to present 3 lines of context and may be changed, e.g., to 10, by.Fl c10 .With.Fl cthe output format is modified slightly:the output beginning with identification of the files involved andtheir creation dates and then each change is separatedby a line with a dozen *'s.The lines removed from.Ar file1are marked with `\(mi '; those added to.Ar file2are marked `+ '. Lines which are changed from onefile to the other are marked in both files with `! '.Changes which lie within <context> lines of each other are groupedtogether on output. (This is a change from the previous ``diff -c''but the resulting output is usually much easier to interpret.).It Fl eproduces output in a form suitable as input for the editor utility,.Xr ed 1 ,which can then be used to convert file1 into file2..PpExtra commands are added to the output when comparing directories with.Fl e ,so that the result is a.Xr sh 1script for converting text files which are common to the two directoriesfrom their state in.Ar dir1to their state in.Ar dir2 ..It Fl fidentical output to that of the.Fl eflag, but in reverse order. It cannotbe digested by.Xr ed 1 ..It Fl hInvokes an alternate algorithm which can handle files of very long lengths.There is a trade off. The algorithm can only deal with changes which areclearly delimited and brief. Long sections of changes and overlaps willconfuse it..It Fl nproduces a script similar to that of.Fl e ,but in the opposite order and with a count of changed lines on eachinsert or delete command. This is the form used by.Xr rcsdiff 1 ..It Fl D Ns Ar stringcreates a merged version of.Ar file1and.Ar file2on the standard output, with C preprocessor controls included so thata compilation of the result without defining.Ar stringis equivalentto compiling.Ar file1 ,while defining.Ar stringwill yield.Ar file2 ..El.PpComparison options:.Bl -tag -width Ds.It Fl bcauses trailing blanks (spaces and tabs) to be ignored, and otherstrings of blanks to compare equal..It Fl iignores the case of letters. E.g., ``A'' will compare equal to ``a''..It Fl twill expand tabs in output lines. Normal or.Fl coutput adds character(s) to the front of each line which may screw upthe indentation of the original source lines and make the output listingdifficult to interpret. This option will preserve the original source'sindentation..It Fl wis similar to.Fl bbut causes whitespace (blanks and tabs) to be totally ignored. E.g.,``if\ (\ a\ ==\ b\ )'' will compare equal to ``if(a==b)''..El.PpDirectory comparison options:.Bl -tag -width Ds.It Fl llong output format; each text file.Nm diff Ns \'dis piped through.Xr pr 1to paginate it,other differences are remembered and summarizedafter all text file differences are reported..It Fl rcauses application of.Nm diffrecursively to common subdirectories encountered..It Fl scauses.Nm diffto report files which are the same, which are otherwise not mentioned..It Fl S Ns Ar namere-starts a directory.Nm diffin the middle beginning with file.Ar name ..El.PpIf both arguments are directories,.Nm diffsorts the contents of the directories by name, and then runs theregular file.Nm diffalgorithm, producing a change list,on text files which are different.Binary files which differ,common subdirectories, and files which appear in only one directoryare described as such..PpIf only one of.Ar file1and.Ar file2is a directory,.Nm diffis applied to the non-directory file and the file contained inthe directory file with a filename that is the same as thelast component of the non-directory file..PpIf either.Ar file1or.Ar file2is.Sq Fl ,the standard input isused in its place..Ss Output StyleThe default (without.Fl e ,.Fl c ,or.Fl n.\" -Coptions)output contains lines of these forms, where.Va XX , YY , ZZ , QQare line numbers respective of file order..Pp.Bl -tag -width "XX,YYcZZ,QQ" -compact.It Li XX Ns Ic a Ns Li YYAt (the end of) line.Va XXof.Ar file1 ,append the contentsof line.Va YYof.Ar file2to make them equal..It Li XX Ns Ic a Ns Li YY,ZZSame as above, but append the range of lines,.Va YYthrough.Va ZZof.Ar file2to line.Va XXof file1..It Li XX Ns Ic d Ns Li YYAt line.Va XXdeletethe line. The value.Va YYtells to which line the changewould bring.Ar file1in line with.Ar file1 ..It Li XX,YY Ns Ic d Ns Li ZZDelete the range of lines.Va XXthrough.Va YYin.Ar file1 ..It Li XX Ns Ic c Ns Li YYChange the line.Va XXin.Ar file1to the line.Va YYin.Ar file2..It Li XX,YY Ns Ic c Ns Li ZZReplace the range of specified lines with the line.Va ZZ ..It Li XX,YY Ns Ic c Ns Li ZZ,QQReplace the range.Va XX , Ns YYfrom.Ar file1with the range.Va ZZ , Ns QQfrom.Ar file2 ..El.PpThese lines resemble.Xr ed 1subcommands to convert.Ar file1into.Ar file2 .The line numbers before the action letters pertain to.Ar file1 ;those after pertain to.Ar file2 .Thus, by exchanging.Ic afor.Ic dand reading the line in reverse order, one can alsodetermine how to convert.Ar file2into.Ar file1 .As in.Xr ed 1 ,identicalpairs (where num1 = num2) are abbreviated as a singlenumber..Sh ENVIRONMENT.Bl -tag -width TMPDIR.It Ev TMPDIRIf the environment variable.Ev TMPDIRexists,.Nm diffwill use the directory specified by.Ev TMPDIRas the temporary directory..El.Sh FILES.Bl -tag -width /usr/bin/diffh -compact.It Pa /tmp/d?????.It Pa /usr/bin/diffhAlternate algorithm version (used by option.Fl h ) ..It Pa /usr/bin/difffor directory diffs.It Pa /usr/bin/prused by the.Fl loption..El.Sh SEE ALSO.Xr cmp 1 ,.Xr cc 1 ,.Xr comm 1 ,.Xr ed 1 ,.Xr diff3 1.br.ne 1i.Sh DIAGNOSTICSThe.Nm diffutility exits with one of the following values:.Pp.Bl -tag -width Ds -compact -offset indent.It \&0No differences were found..It \&1Differences were found..It "\&>\&1"An error occurred..El.Sh BUGSThe.Fl fand.Fl eoptionsdo not provide special handling for lines on which thefirst and only character is.Dq Li \&. .This can cause problems for.Xr ed 1 ..PpWhen comparing directories with the.Fl b ,.Fl wor.Fl ioptions specified,.Nm difffirst compares the files ala.Ar cmp ,and then decides to run the.Nm diffalgorithm if they are not equal.This may cause a small amount of spurious output if the filesthen turn out to be identical because the only differences areinsignificant white space or case differences..Sh HISTORYA.Nmcommand appeared in.At v6 .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -