1.\" Copyright (c) 1980, 1990 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)diff.1 6.5 (Berkeley) 06/24/90 7.\" 8.Dd 9.Dt DIFF 1 10.Os BSD 4 11.Sh NAME 12.Nm diff 13.Nd differential file and directory comparator 14.Sh SYNOPSIS 15.Nm diff 16.Op Fl l 17.Op Fl r 18.Op Fl s 19.Op Fl cefhn 20.Op Fl biwt 21.Ar dir1 dir2 22.Nm diff 23.Op Fl cefhn 24.Op Fl biwt 25.Ar file1 file2 26.Nm diff 27.Op Fl D Ar string 28.Op Fl biw 29.Ar file1 file2 30.Sh DESCRIPTION 31The 32.Nm diff 33utility compares the contents of 34.Ar file1 35and 36.Ar file2 37and writes to the standard output a minimal list of changes necessary to 38convert one of the files into the other. 39No output is produced if the files are identical. 40.Pp 41If both arguments are directories, 42.Nm diff 43sorts the contents of the directories by name, and then runs the 44regular file 45.Nm diff 46algorithm, producing a change list, 47on text files which are different. 48Binary files which differ, 49common subdirectories, and files which appear in only one directory 50are described as such. 51.Pp 52If only one of 53.Ar file1 54and 55.Ar file2 56is a directory, 57.Nm diff 58is applied to the non-directory file and the file contained in 59the directory file with a filename that is the same as the 60last component of the non-directory file. 61.Pp 62If either the 63.Ar file1 64or 65.Ar file2 66is 67.Fl , 68the standard input is 69used in its place. 70.Pp 71Options when comparing directories are: 72.Tw Fl 73.Tp Fl l 74long output format; each text file 75.Sf Nm diff \'d 76is piped through 77.Xr pr 1 78to paginate it, 79other differences are remembered and summarized 80after all text file differences are reported. 81.Tp Fl r 82causes application of 83.Nm diff 84recursively to common subdirectories encountered. 85.Tp Fl s 86causes 87.Nm diff 88to report files which are the same, which are otherwise not mentioned. 89.Tc Fl S 90.Ar name 91.Cx 92starts a directory 93.Nm diff 94in the middle beginning with file 95.Ar name . 96.Tp 97.Pp 98Output options. Except for 99.Fl b , 100.Fl w , 101.Fl i 102or 103.Fl t 104which may be given with any of the others, 105the following options are mutually exclusive: 106.Tw Fl 107.Tp Fl c 108produces a diff with lines of context. 109The default is to present 3 lines of context and may be changed, e.g to 10, by 110.Fl c10 . 111With 112.Fl c 113the output format is modified slightly: 114the output beginning with identification of the files involved and 115their creation dates and then each change is separated 116by a line with a dozen *'s. 117The lines removed from 118.Ar file1 119are marked with `\(mi '; those added to 120.Ar file2 121are marked `+ '. Lines which are changed from one 122file to the other are marked in both files with with `! '. 123Changes which lie within <context> lines of each other are grouped 124together on output. (This is a change from the previous ``diff -c'' 125but the resulting output is usually much easier to interpret.) 126.Tp Fl e 127produces output in a form suitable as input for the editor utility, 128.Xr ed 1 , 129which can then be used to convert file1 into file2. 130.Pp 131Extra commands are added to the output when comparing directories with 132.Fl e , 133so that the result is a 134.Xr sh 1 135script for converting text files which are common to the two directories 136from their state in 137.Ar dir1 138to their state in 139.Ar dir2 . 140.Tp Fl f 141identical output of the 142.Fl e 143flag, but in reverse order. It cannot 144be digested by 145.Xr ed 1 . 146.Tp Fl h 147Invokes an alternate algorithm which can handle files of very long lengths. 148There is a trade off. The algorithm can only deal with changes which are 149clearly delimited and brief. Long sections of changes and overlaps will 150confuse it. 151.Tp Fl n 152produces a script similar to that of 153.Fl e , 154but in the opposite order and with a count of changed lines on each 155insert or delete command. This is the form used by 156.Xr rcsdiff 1 . 157.Tc Fl D 158.Ar string 159.Cx 160causes 161.Nm diff 162to create a merged version of 163.Ar file1 164and 165.Ar file2 166on the standard output, with C preprocessor controls included so that 167a compilation of the result without defining 168.Ar string 169is equivalent 170to compiling 171.Ar file1 , 172while defining 173.Ar string 174will yield 175.Ar file2 . 176.Tp Fl b 177causes trailing blanks (spaces and tabs) to be ignored, and other 178strings of blanks to compare equal. 179.Tp Fl i 180ignores the case of letters. E.g., ``A'' will compare equal to ``a''. 181.Tp Fl t 182will expand tabs in output lines. Normal or 183.Fl c 184output adds character(s) to the front of each line which may screw up 185the indentation of the original source lines and make the output listing 186difficult to interpret. This option will preserve the original source's 187indentation. 188.Tp Fl w 189is similar to 190.Fl b 191but causes whitespace (blanks and tabs) to be totally ignored. E.g., 192``if\ (\ a\ ==\ b\ )'' will compare equal to ``if(a==b)''. 193.Tp 194.Ss Output Style 195The default (without 196.Fl e , 197.Fl c , 198.Fl n , 199or 200.Fl t 201.\" -C 202options) diff utility 203output contains lines of these forms, where 204.Va XX , YY , ZZ , QQ 205are line numbers respective of file order. 206.Pp 207.Dp Cx Li XX 208.Ic a 209.Li YY 210.Cx 211At (the end of) line 212.Va XX 213of 214.Ar file1 , 215append the contents 216of line 217.Va YY 218of 219.Ar file2 220to make them equal. 221.Dp Cx Li XX 222.Ic a 223.Li YY , 224.Li ZZ 225.Cx 226Same as above, but append the range of lines, 227.Va YY 228through 229.Va ZZ 230of 231.Ar file2 232to line 233.Va XX 234of file1. 235.Dp Cx Li XX 236.Ic d 237.Li YY 238.Cx 239At line 240.Va XX 241delete 242the line. The value 243.Va YY 244tells to which line the change 245would bring 246.Ar file1 247in line with 248.Ar file1 . 249.Dp Cx Li XX , 250.Li YY 251.Ic d 252.Li ZZ 253.Cx 254Delete the range of lines 255.Va XX 256through 257.Va YY 258in 259.Ar file1 . 260.Dp Cx Li XX 261.Ic c 262.Li YY 263.Cx 264Change the line 265.Va XX 266in 267.Ar file1 268to the line 269.Va YY 270in 271.Ar file2. 272.Dp Cx Li XX , 273.Li YY 274.Ic c 275.Li ZZ 276.Cx 277Replace the range of specified lines with the line 278.Va ZZ . 279.Dp Cx Li XX , 280.Li YY 281.Ic c 282.Li ZZ , 283.Li QQ 284.Cx 285Replace the range 286.Cx Va XX , 287.Va YY 288.Cx 289from 290.Ar file1 291with the range 292.Cx Va ZZ , 293.Va QQ 294.Cx 295from 296.Ar file2 . 297.Dp 298.Pp 299These lines resemble 300.Xr ed 1 301subcommands to convert 302.Ar file1 303into 304.Ar file2 . 305The line numbers before the action letters pertain to 306.Ar file1 ; 307those after pertain to 308.Ar file2 . 309Thus, by exchanging 310.Ic a 311for 312.Ic d 313and reading the line in reverse order, one can also 314determine how to convert 315.Ar file2 316into 317.Ar file1 . 318As in 319.Xr ed 1 , 320identical 321pairs (where num1 = num2) are abbreviated as a single 322number. 323.Sh ENVIRONMENT 324.Tw Fl 325.Tp Ev TMPDIR 326If the environment variable 327.Ev TMPDIR 328exists, 329.Nm Diff 330will use the name specified by 331.Ev TMPDIR 332as an alternate temporary directory. 333.Tp 334.Sh FILES 335.Dw /usr/bin/diffh 336.Di L 337.Dp Pa /tmp/d????? 338.br 339.Dp Pa /usr/bin/diffh 340Alternate algorithm version (used by option 341.Fl h ) . 342.Dp Pa /usr/bin/diff 343for directory diffs 344.Dp Pa /usr/bin/pr 345used by the 346.Fl l 347option. 348.Dp 349.Sh SEE ALSO 350.Xr cmp 1 , 351.Xr cc 1 , 352.Xr comm 1 , 353.Xr ed 1 , 354.Xr diff3 1 355.Sh HISTORY 356.Nm Diff 357appeared in Version 6 AT&T Unix. 358.Sh DIAGNOSTICS 359The 360.Nm diff 361utility exits with one of the following values: 362.Dw Ds 363.Dp \&0 364No differences were found. 365.Dp \&1 366Differences were found. 367.Dp \&>\&1 368An error occurred. 369.Dp 370.Sh BUGS 371The 372.Fl f 373and 374.Fl e 375options 376have difficulties producing lines with the 377first and only character 378.Dq Li \&. , 379as this is a command character for 380.Xr ed 1 . 381.Pp 382When comparing directories with the 383.Fl b , 384.Fl w 385or 386.Fl i 387options specified, 388.Nm diff 389first compares the files ala 390.Ar cmp , 391and then decides to run the 392.Nm diff 393algorithm if they are not equal. 394This may cause a small amount of spurious output if the files 395then turn out to be identical because the only differences are 396insignificant blank string or case differences. 397.\" .Sh STANDARDS 398