diff 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. .TH DIFF 1
  2. .SH NAME
  3. diff \- differential file comparator
  4. .SH SYNOPSIS
  5. .B diff
  6. [
  7. .B -abcefmnrw
  8. ]
  9. .I file1 ... file2
  10. .SH DESCRIPTION
  11. .I Diff
  12. tells what lines must be changed in two files to bring them
  13. into agreement.
  14. If one file
  15. is a directory,
  16. then a file in that directory with basename the same as that of
  17. the other file is used.
  18. If both files are directories, similarly named files in the
  19. two directories are compared by the method of
  20. .I diff
  21. for text
  22. files and
  23. .IR cmp (1)
  24. otherwise.
  25. If more than two file names are given, then each argument is compared
  26. to the last argument as above.
  27. The
  28. .B -r
  29. option causes
  30. .I diff
  31. to process similarly named subdirectories recursively.
  32. When processing more than one file,
  33. .I diff
  34. prefixes file differences with a single line
  35. listing the two differing files, in the form of
  36. a
  37. .I diff
  38. command line.
  39. The
  40. .B -m
  41. flag causes this behavior even when processing single files.
  42. .PP
  43. The normal output contains lines of these forms:
  44. .IP "" 5
  45. .I n1
  46. .B a
  47. .I n3,n4
  48. .br
  49. .I n1,n2
  50. .B d
  51. .I n3
  52. .br
  53. .I n1,n2
  54. .B c
  55. .I n3,n4
  56. .PP
  57. These lines resemble
  58. .I ed
  59. commands to convert
  60. .I file1
  61. into
  62. .IR file2 .
  63. The numbers after the letters pertain to
  64. .IR file2 .
  65. In fact, by exchanging `a' for `d' and reading backward
  66. one may ascertain equally how to convert
  67. .I file2
  68. into
  69. .IR file1 .
  70. As in
  71. .IR ed ,
  72. identical pairs where
  73. .I n1
  74. =
  75. .I n2
  76. or
  77. .I n3
  78. =
  79. .I n4
  80. are abbreviated as a single number.
  81. .PP
  82. Following each of these lines come all the lines that are
  83. affected in the first file flagged by `<',
  84. then all the lines that are affected in the second file
  85. flagged by `>'.
  86. .PP
  87. The
  88. .B -b
  89. option causes
  90. trailing blanks (spaces and tabs) to be ignored
  91. and other strings of blanks to compare equal.
  92. The
  93. .B -w
  94. option causes all white-space to be removed from input lines
  95. before applying the difference algorithm.
  96. .PP
  97. The
  98. .B -n
  99. option prefixes each range with
  100. .IB file : \fR
  101. and inserts a space around the
  102. .BR a ,
  103. .BR c ,
  104. and
  105. .B d
  106. verbs.
  107. The
  108. .B -e
  109. option produces a script of
  110. .I "a, c"
  111. and
  112. .I d
  113. commands for the editor
  114. .IR ed ,
  115. which will recreate
  116. .I file2
  117. from
  118. .IR file1 .
  119. The
  120. .B -f
  121. option produces a similar script,
  122. not useful with
  123. .IR ed ,
  124. in the opposite order. It may, however, be
  125. useful as input to a stream-oriented post-processor.
  126. .PP
  127. The
  128. .B -c
  129. option includes three lines of context around each
  130. change, merging changes whose contexts overlap.
  131. In this mode,
  132. .I diff
  133. prints
  134. .L -
  135. and
  136. .L +
  137. instead of
  138. .L <
  139. and
  140. .L >
  141. because the former are easier to distinguish when mixed.
  142. The
  143. .B -a
  144. flag displays the entire file as context.
  145. .PP
  146. Except in rare circumstances,
  147. .I diff
  148. finds a smallest sufficient set of file
  149. differences.
  150. .SH FILES
  151. .B /tmp/diff[12]
  152. .SH SOURCE
  153. .B /sys/src/cmd/diff
  154. .SH "SEE ALSO"
  155. .IR cmp (1),
  156. .IR comm (1),
  157. .IR ed (1),
  158. .IR idiff (1)
  159. .SH DIAGNOSTICS
  160. Exit status is the empty string
  161. for no differences,
  162. .L some
  163. for some,
  164. and
  165. .L error
  166. for trouble.
  167. .SH BUGS
  168. Editing scripts produced under the
  169. .BR -e " or"
  170. .BR -f " option are naive about"
  171. creating lines consisting of a single `\fB.\fR'.
  172. .PP
  173. When running
  174. .I diff
  175. on directories, the notion of what is a text
  176. file is open to debate.